Android VideoView, seamless playback during orientation change - android

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.

Related

How to adjust camera parameters for a video recording in cwac-camera?

My app has a fixed UI orientation. Because of that, when a video is recorded, it always has the same orientation embedded in the video. However, I would like to set the orientation to what the sensors tell me instead of the getWindowManager().getDefaultDisplay().getRotation();
Here are some of my findings:
There is no adjustPictureParamaters() method (like there is for the pictures) on the CameraHost that would update the video recording parameters
Extending and overriding methods on the CameraView is not possible because some of the methods are private.
I could create my own custom branch of the cwac code and update the logic but I really don't want to maintain a separate branch just for something minor like this.
Reprocessing the video and updating orientation after it's recorded takes some extra time.
For now I will probably go with #4. But is there a better solution for this?
There is no adjustPictureParamaters() method (like there is for the pictures) on the CameraHost that would update the video recording parameters
There is no way to update the video recording parameters in the way that you seek AFAIK. Video recording, more so than still picture recording, is up to the device, not us.
Extending and overriding methods on the CameraView is not possible because some of the methods are private.
Moreover, none of them would help you in this case.
I could create my own custom branch of the cwac code and update the logic but I really don't want to maintain a separate branch just for something minor like this.
Moreover, none of that would help you in this case.
Reprocessing the video and updating orientation after it's recorded takes some extra time.
That is the only option that I know of.

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.

VideoView restarts playback on lock screen

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.

How to programmatically change the z-order of VideoViews in Android

I have an android app with a RelativeLayout, to which I programmatically add multiple VideoViews, all of which are playing at the same time. The VideoViews can be moved around by dragging, and they can be moved so that they overlap.
The problem is that I cannot find a way to change the z-order of them during the runtime. .bringToFront() brings the view to front for receiving touch events, however the order of the actual videos remains the same.
I have tried removing and re-adding the videoView by .removeChild(), however that stops and resets the video.
Is there a way to change the z-order of the videos? A "hacky" way would work too, e.g. removing ad re-adding the view without stopping and resetting the video.
Thanks
P.S. It's a streaming video, so restarting the video to the same position would not work, there would be way too big delay.
EDIT: Even though people suggest multiple VideoViews should not work, they do work great, even overlapping, at least on my Nexus S, ICS 4.0.3
EDIT 2: Actually, not great, the second video sometimes flickers, but that's fine for this purpose. The 3rd and 4th video don't flicker, which is a bit weird
The document says the Z-order of SurfaceView's are determined before they are attached to window, and their orders are not altered once attached. Since VideoView's are also SurfaceView, I don't think it is possible to do it.
The VideoViews use SurfaceView, witch is Z-ordered with the windows, but you cannot have multiple SurfaceView z-ordered,because every SurfaceView will punches a hole on the window. If you add multiple video on the same area, video will not play correctly. I used to translate video out off the screen to keep its state. Look for EcoNews aap on google play.

Categories

Resources