Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Video restarts after orientation changes

Tags:

android

I am playing video in android using VideoView by using different activity other than main activity.

At the time of video is running when i changes the orientation of phone it stops that video then project run from main activity and later video starts from beginning. Even to play video from beginning it taking too much time .

Can i play video immediately and from that position where it stops when orientation changes.

Please suggest me solution.

Thanks in advance.

Nilesh.

like image 653
Nilesh Bajbalkar Avatar asked Aug 02 '11 06:08

Nilesh Bajbalkar


3 Answers

Override the following Method in your activity

 @Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    System.out.println("IN onConfigurationChanged()");
}

and add the following property in your manifest file in your activity tag

android:configChanges="orientation"
like image 75
Usman Kurd Avatar answered Sep 21 '22 13:09

Usman Kurd


You can save the current position of the video using VideoView.getCurrentPostion() in onSavedInstance() method. And can start the video using VideoView.seek(pos) and then VideoView.start()

Note: run the seek() and start() methods in a thread.

like image 23
sachy Avatar answered Sep 19 '22 13:09

sachy


To help any stumbler

if your android:targetSdkVersion="12" or less

android:configChanges="orientation|keyboardHidden">

if your android:targetSdkVersion="13" or more

android:configChanges="orientation|keyboardHidden|screenSize">

Reference: See Mohit comment on this question Android application restarts on orientation change

like image 32
Tezro Solutions Avatar answered Sep 20 '22 13:09

Tezro Solutions