VideoView restarts playback on lock screen - android

I have an activity containing a vitamio VideoView, it works pretty well except for a annoying issue that causes the player to restart playback when I lock the screen.
As far as I can see it actually kills the activity upon locking and then restarts it.
Anyone have an idea on how I can fix this issue?
Thanks in advance,
X

What I ended up doing was adding android:configChanges="orientation|screenSize"
to my manifest. And I added videoView.pause(); to my onPause() function in the VideoView activity to make sure it didn't continue playing.
Even though this worked I believe you must force the orientation for the VideoView activity, unless you want it to look weird when the orientation changes.

Related

Android TV - Prevent Screen Saver From Appearing

I am creating a standard Android TV app which plays some videos and ran into an issue where screen saver turns on while I'm watching a video.
How can I prevent that from happening? Is there any trigger which I can trigger when I want for a screen to be ON all the time and prevent screen saver from appearing?
This looks like a good solution but screen saver still appears:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); works on any device when it is set at the beginning of your activity. Where is that code being set? Is it in your main activity or also in your video playback activity?
You can take a look at the Keeping the Device Awake guide for more information.
If you are using a SurfaceView to display your video, you should call .setKeepScreenOn(true); method of the SurfaceView instance.

Android focus and exposure stops working with FOCUS_MODE_CONTINUOUS_PICTURE

I'm making a small camera app, and I'm having a little problem with capturing several pictures.
First I found that after every mCamera.takePicture() we need to call mCamera.startPreview() on onPictureTaken() callback to keep seeing the preview after the first shot.
So, after this discovery, I've added a code to set the camera focus mode to FOCUS_MODE_CONTINUOUS_PICTURE in initialization, because it was not getting focus automatically.
What happens is that Auto Exposure and Auto Focus stop to work after the first shot.
I found that the Auto Exposure and Auto Focus works for a brief time after the shots and blocks.
Is there any function I need to call to restart this features after a shot?
Thank you.
This answer will probably work for you:
I fixed the issue by calling camera.cancelAutoFocus(). This caused continuous autofocus to kick in again.
After you take the shot, call camera.cancelAutoFocus()

Video Freeze after lock screen on SurfaceView using SurfaceView and MediaPlayer

I was trying to use SurfaceView and MediaPlayer to Display video on Android.
I got a bug now that if I press the power button to lock the screen and then unlock it, The Video displayed on the MediaPlayer is gone and there is only sound. Normally for this situation the surfaceView would be somehow freeze to the last frame of the video before I lock the phone.
It works fine when I hide the screen(such as go to home and open another application) But it just does not work when I lock the phone. I think they both pass the onPause and onResume so I do not understand why would there be different logic.
I'd like to know if there is a solution to solve my problem.
Thanks!
I'm not sure exactly what's going on, but there's a general class of problem that is likely the cause of your trouble.
If your lockscreen is orientation-independent, or wants to be oriented the same way the device is, then the Activity won't be restarted to change orientation. In this case, turning the display off and back on with the power button won't cause the SurfaceView's surface to be destroyed. So if your app is relying on the surfaceCreated and surfaceChanged callbacks to fire to make things happen, then things won't happen.
If you leave the Activity and come back, the Surface does get destroyed and re-created.
The relationship between the Activity lifecycle and the Surface lifecycle is a bit complicated; you can find some notes about it in this article, including two basic patterns for structuring an app. Examples of both "styles" of SurfaceView management can be found in Grafika.
I can't make specific recommendations without knowing how your app works, but mainly you just need to look at what your app does with the idea that Activity and Surface lifetimes are not tightly coupled.
OK, I fix this in a weird way, I think it is probably a bug of Android. Don't have time to do enough testing on this.
First surely as #fadden says you need to have a mMediaPlayer.setDisplay(myHolder) elsewhere not in the surfaceChanged or surfaceCreated since they may not be called while resume from locked screen.
For me the problem still persist after I changed it this way. Here is what I changed that solved the problem: Instead of mMediaPlayer = new MediaPlayer(), we should use mMediaPlayer = MediaPlayer.create(MediaActivity.this, fileUri)

Android tablet with embedded VideoView loses video on rotation

I'm looking for a solution to continue playing a video for a URL (*.mp4/playlist.m3u8) in an embedded VideoView on a tablet when the device is rotated.
Currently, the video is being restarted on rotation using onPause() and onResume().
As I understand it, a lot of solutions require using android:configChanges="orientation|screenSize", but Android's developer site suggests using this only as a last resort.
See Handling Runtime Changes.
This technique should be considered a last resort when you must avoid restarts due to a configuration change and is not recommended for most applications.
Is there another way to do this? How would I go about keeping the video playing through rotation like how a Phone device does when using Intents?
Edit: I also want to mention that the other reason I am avoiding use of android:configChanges is because I have different layouts for landscape and portrait, and I do not wish to handle the layout changes manually.
Edit 2: I have come up with a way to get configChanges to work when using different layouts by using SurfaceView within the layouts and handling the layout change in onConfigurationChanged with setContentView and MediaPlayer to switch its display when the layout is changed.
Now, I just need a way to retain the MediaPlayer across orientation changes.

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
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.

Categories

Resources