I have a MediaPlayer playing Video and everything works fine except for when you lock the screen and then unlock it, the Video will restart.
Currently I’m using
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();
And it works but if the you press the Home button you will not be able to lock the screen because the application has turned it off. Do you know a better approach to keep the progress of a video without having to use the KeyGuardLock?
Instead of KeyGuard you can just simply use
android:keepScreenOn=trueon yourVideoViewin the layout xml.For the latter part, you have to save the video’s progress in
onSaveInstanceState()and load the progress data inonRestoreInstanceState(), than you can just useseekTo(progress)on your video with the data you just got back.Also don’t forget to check for null in
onRestoreInstanceState()in case it is a new playback.