Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android VideoView, seamless playback during orientation change

I'm using a VideoView to play a mp4 file in my application. Is there a way to save all the content that was buffered so when the orientation of the screen is changed the user doesn't have to wait another 10 seconds or more for the video to start playing again.

Perhaps "saving the buffered video" isn't the right solution, I'm just looking for a way to have the playback almost appear seamless when the orientation of the screen is changed.

I'm already saving the video positioning and using the "seekTo" method to start the video where it left off. But I'm looking to prevent the rebuffering as well. I searched all over stackoverflow and couldn't find any discussions on this.

Thanks!

Bradley4

like image 797
bradley4 Avatar asked Jun 25 '11 00:06

bradley4


People also ask

How to handle screen orientation changes in Android?

There are a different options to handle the orientation changes: 1. Lock screen orientation 2. Prevent Activity to recreated 3. Save basic state 4. Save complex objects To lock the screen orientation change of any screen (activity) of your android application makes your activity display only in one mode i.e. either Landscape or Portrait.

How to lock the screen orientation change of any activity?

To lock the screen orientation change of any screen (activity) of your android application makes your activity display only in one mode i.e. either Landscape or Portrait. This is the simplest way to handle screen orientation but not generally recommended. For this you need to add below line in your projects AndroidManifest.xml.

Does mediaplayer pause the video when the device orientation changes?

In other words, the video does not need to be paused, re-buffered, or reloaded, and does not skip or drop any audio frames when the device orientation changes. This method uses a TextureView and its accompanying SurfaceTexture as a sink for the MediaPlayer 's current video frame.

How does the videoview overlay work?

That overlay is behind the window holding the VideoView. VideoView punches a hole in its window so that the overlay is visible. It then keeps it in sync with the layout (eg. if you move or resize VideoView, the overlay has to be moved and resized as well).


1 Answers

You could handle the configuration change yourself so that the application isn't restarted.

Another solution might be to put the VideoView into a Fragment. Then rather than killing the Fragment with the Activity, you might just pause the video detach the Fragment and re-attach after the configuration change. Although now that I think about it, I think the Fragment may also be re-created on the configuration change...

Very interested in how you solve this, please post your solution if no one answers.

like image 79
Spidy Avatar answered Sep 24 '22 07:09

Spidy