Ronnie
Ronnie

Reputation: 11198

Rotating phone restarts video on android

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?

Upvotes: 10

Views: 10550

Answers (5)

imnhasan
imnhasan

Reputation: 115

You Should try this. Go to your AndroidManifest.xml file then past it tag.

<activity android:name=".activity_name"
 android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

Upvotes: 0

Ashok
Ashok

Reputation: 601

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"

Upvotes: 27

user468311
user468311

Reputation:

Consider remembering video file position in Activity lifecycle events. When Activity is created you could obtain video position and play it from the moment it was restarted.

In your 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
}

Upvotes: 3

lomec
lomec

Reputation: 1354

ConfigChanges is right, but it did work like this;

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

and also in the Activity Class

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

Upvotes: 0

Peter Knego
Peter Knego

Reputation: 80330

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

Upvotes: 1

Related Questions