I want to write Android application that will play HLS video. I use default VideoView control for this:
VideoView player = (VideoView) findViewById(R.id.player);
String httpLiveUrl = "http://example.com/playlist.m3u8";
player.setVideoURI(Uri.parse(httpLiveUrl));
player.setMediaController(new MediaController(this));
player.requestFocus();
player.start();
Everything works fine until you change device orientation (rotate it). In this case Android will destroy current activity with VideoView instance and downloaded HLS fragments. New activity instance will be created from scratch. Hence, VideoView (MediaPlayer) must establish connection and download HLS fragments again (that takes a lot of time). More over, video will be started not from current position, but from beginning.
I know about activity’s methods that helps to save/restore activity’s state like onSaveInstancestate/onRestoreInstanceState, but I have no idea how can I serialize VideoView to carry him through orientation change.
I even thought about Android Service for MediaPlayer… but I think it is bad and incorrect way in case of video player.
So, do anyone have any idea? 🙂
You can :
1: Fix the orientation by specifying it in the Manifest file:
2: You can tell android to keep your app running even after orientation changes.
In this case the activity will not be destroyed and re-created.