3

I used videoview for playing a video in android default player. When I change its orientation, it starts playing from beginning.

How could I make it to continue from that point, where orientation changed ?

Anwar
  • 1,755
  • 1
  • 21
  • 32
sanjay
  • 2,590
  • 17
  • 55
  • 88

2 Answers2

17

Add:

<activity
    android:name="...your_activity..."
    android:configChanges="screenSize|orientation|keyboardHidden"
/>

to the AndroidManifest file, to the Activity that handles video play back.

Andy Res
  • 15,963
  • 5
  • 60
  • 96
  • Ive tried this.but its UI fits for landscape well.But again video starts playing from beginning – sanjay Jul 24 '12 at 11:16
  • Are you sure you are not missing the "orientation" attribute in configChanges? – Andy Res Jul 24 '12 at 11:17
  • i can able to use like this on manifest android:configChanges="orientation|screenLayout|keyboardHidden" I cant able to use screeSize – sanjay Jul 24 '12 at 11:23
4

When you change the orientation the OS destroys your activity, and recreates it.

You can save the actual progress of the video in onSaveInstanceState() and get the saved data in onRestoreInstanceState() from the Bundle, after that you can start the playing with either the progress data, or from the beginning if there was no data saved.

Adam Monos
  • 4,287
  • 1
  • 23
  • 25
  • @Adam L. Mónos, It is good. But video is buffering while changing the orientation. It shouldn't happen. Can you please tell me how to overcome this? – Noundla Sandeep Mar 07 '13 at 09:58
  • If you are loading the video in an `AsyncTask` then you have to cancel the loading manually in `onPause()` and start/restart it in `onResume()`. Though I don't really see the problem with this behaviour. If you need more sophisticated help, you should open a new question. – Adam Monos Mar 07 '13 at 10:57