Rotating phone restarts video on android
Solution 1
add
android:configChanges="orientation"
to your Activity in AndroidManifest.xml.
- solved my issue won't download progressive video again..
If your target API level 13 or higher, you must include the screenSize
value in addition to the orientation
value as described here. So your tag may look like
android:configChanges="orientation|screenSize"
Solution 2
Adding the configChanges
attribute to your manifest means that you will handle config changes yourself. Override the onConfigurationChanged()
method in your activity:
int lastOrientation = 0;
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks if orientation changed
if (lastOrientation != newConfig.orientation) {
lastOrientation = newConfig.orientation;
// redraw your controls here
}
}
Ronnie
Updated on June 25, 2022Comments
-
Ronnie almost 2 years
When I rotate my phone, my Activity restarts. I have a video view playing video, I rotate and the video restarts. Now I found adding this to my activity in the manifest fixed it
<activity android:name="Vforum" android:configChanges="orientation"></activity>
The problem now is the video controls aren't being redrawn until they disappear and come back, thus leaving either really long controls going from landscape to portrait mode or really short controls going from portrait to landscape. Once they disappear and then I tap to make them come back, then they are correctly sized. Is there a better method of doing this?
-
Ronnie about 13 yearsOhhh ok gotcha! I'm only on my second week of java so bare with me....how do I redraw the controls now? I tried
mVideoView.refreshDrawableState();
and failed. I dont know what method redraws them. -
Peter Knego about 13 yearsYou don't want to recreate whole view as this will kill the video player. You need to replace only parts that need to change (controls) and leave player intact. Basically you will: locate the parent view group (layout), get positions of views to be replaced (index), remove them, inflate new ones, add to same position: stackoverflow.com/questions/3334048/…
-
Ronnie about 13 yearsI am using the standard MediaController though. I don't want any layout to change. Its the built in video controls that need to be redrawn. I posted a video of what is happening: youtube.com/watch?v=FgRythmUo3A
-
Ronnie about 13 yearsany idea after watching the video?
-
Ronnie almost 6 yearsI asked this question 7 years ago so I am sure things have changed. Still, thank you for your response.