Reputation: 51
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.
Upvotes: 5
Views: 4226
Reputation: 789
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.
Upvotes: 5
Reputation: 431
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
Upvotes: 4
Reputation: 7023
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"
Upvotes: 5
Reputation: 222
add
android:configChanges="orientation"
to your Activity in AndroidManifest.xml.
-thanks to user 'Ashok' source : Rotating phone restarts video on android
Upvotes: 0