5

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.

4 Answers4

5

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.

ern0
  • 3,074
  • 25
  • 40
sachy
  • 739
  • 7
  • 13
5

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"
Usman Kurd
  • 7,212
  • 7
  • 57
  • 86
  • 1
    Thanks Usman, your solution work for me. all who read this please please give a "up vote" for any one solution which work for you so other can get help. – saqibahmad May 11 '15 at 14:13
3

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

Community
  • 1
  • 1
Tezro Solutions
  • 411
  • 6
  • 17
0

add

android:configChanges="orientation"

to your Activity in AndroidManifest.xml.

-thanks to user 'Ashok' source : Rotating phone restarts video on android

Community
  • 1
  • 1
rbertsch8
  • 222
  • 2
  • 12