Rotating Phone Restarts Android Video

Hey guys, when I turn my phone on, my activity restarts. I have a video playing a video, I rotate and the video restarts. Now I found that I added this to my activity in the manifest, fixing it

<activity android:name="Vforum" android:configChanges="orientation"></activity> 

Now the problem is that the video controls are not redrawn until they disappear and return, and thus they leave either very long controls that go from landscape to portrait mode or very short controls, going from portrait to landscape. As soon as they disappear, and then I touch them so that they return, then they have the correct size. Is there a better way to do this?

+8
android controls video videoview
source share
4 answers

add

android:configChanges="orientation"

for your activity in AndroidManifest.xml.

  • decided that my problem would not upload progressive video again.

If your target API level is 13 or higher, you should add a screenSize value in addition to the orientation value, as described here , so your tag might look like

 android:configChanges="orientation|screenSize" 
+21
source share

Consider the possibility of remembering the position of the video file in the events of the activity life cycle. When an action is created, you can get the position of the video and play it from the moment it is restarted.

In the Activity class:

 @Override protected void onCreate(Bundle bundle){ super.onCreate(bundle); int mPos=bundle.getInt("pos"); // get position, also check if value exists, refer to documentation for more info } @Override protected void onSaveInstanceState (Bundle outState){ outState.putInt("pos", myVideoView.getCurrentPosition()); // save it here } 
+3
source share

Adding the configChanges attribute to your manifest means that you change the descriptor configuration . 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 } } 
+1
source share

ConfigChanges is right, but it works like this:

  <activity android:configChanges="orientation|screenSize" ... > 

as well as in the activity class

 @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (lastOrientation != newConfig.orientation) { lastOrientation = newConfig.orientation; // redraw your controls here } } 
0
source share

All Articles