Video resumes when orientation changes

I wrote code to play videos from my site.

It works correctly, but when I rotate my phone, the video resumes from the very beginning.

How can i solve this?

public class ActivityVideoDetail extends Activity {

    private VideoDetail videoDetail;
    private TextView    txtResult;
    // -------------------------
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_activity_video_detail);
        if (savedInstanceState != null)
        {

        }
        else {
            ini();
        }
    }


    // -------------------------
    private void ini() {
        videoDetail = (VideoDetail) getIntent().getExtras().getSerializable(VideoDetail.VIDEO_DETAIL);
        txtResult = (TextView) findViewById(R.id.txtResult);
        txtResult.setText(videoDetail.getVideoTitle());

        Uri uri = Uri.parse(videoDetail.getVideoPath());
        //   Uri uri = Uri.parse("http://daily3gp.com/vids/747.3gp");

        VideoView videoView = (VideoView) findViewById(R.id.videoPlayer);

        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        mediaController.setMediaPlayer(videoView);

        videoView.setMediaController(mediaController);
        videoView.setVideoURI(uri);
        videoView.start();
    }
}
+4
source share
3 answers

You just need to go to AndroidManifest.xml and inside or in your action shortcuts, you have to type this line of code, as someone said there:

android:configChanges="orientation|screenSize"

So you will have something like this:

<activity android:name="ActivityMenu"
android:configChanges="orientation|screenSize">
</activity>

Hope this works for you.

There are usually three ways to do this:

, savedInstanceState. onSaveInstanceState onCreate.

, : screenOrientation = "" ( "" ).

, , android: configChanges = "screenOrientation".. , , ( , ).

+6

Android: configChanges = " | | keyboardHidden"

<activity>

0

When you rotate the screen, the onCreate method is called again.

http://i.stack.imgur.com/z8GHs.png

Add this flag to your manifest

android:configChanges="orientation"
0
source

All Articles