In Android, the Activity isn't seeing the orientation change?

I've got a simple Activity that plays a video.

        uriStr = ("http://pathToVideo.com/video/" + yyyyMdd_Str + "/" + yyyyMdd_Str +       ".mp4");

    VideoView testVideo1_VV =(VideoView) findViewById(R.id.videoTest7vid_VV);
    testMediaCon1_MC = new MediaController(this);
    testMediaCon1_MC.setAnchorView(testVideo1_VV);
    testVideo1_VV.setMediaController(testMediaCon1_MC);
    testVideo1_VV.setKeepScreenOn(true);
    testVideo1_VV.setVideoPath(uriStr);
    testVideo1_VV.requestFocus();
    testVideo1_VV.start();

In the portrait layout, the video is aligned to the top so that it plays in the top third of the screen, and in the landscape layout, the video is full screen by wrapping content on both height and width. In the Manifest I've set android:configChanges="orientation" so that the Activity doesn't refresh on orientation change. But my problem is that the layout doesn't change with orientation change. How can I keep the video playing when the orientation changes, but also get the correct layout to display on orientation change?

So now I think the solution is to note the video's position on playback and then use savedInstanceState to retrieve the video state and start the video from that point upon orientation change. Something like this:

    @Override
protected void onSaveInstanceState(Bundle out) {

 super.onSaveInstanceState(out);
//video state would go here
}

@Override
protected void onRestoreInstanceState(Bundle in) {

 super.onRestoreInstanceState(in);
 //video state would go here
}

But now I don't know the code to grab the video's state...


When you set android:configChanges="orientation" you are explicitly telling the Android OS you will handle orientation changes yourself, including switching layouts etc as necessary so you need to implement onConfigurationChanged() in your activity and take care of any changes you want to make there.

Also worth noting that android:configChanges="orientation" only takes care of the landscape -> portrait change, not portrait to landscape. Try changing orientation to orientation|keyboardHidden to handle both situations.


Android: alternate layout xml for landscape mode to have a different layout according to orientation.

And you need some way to bookmark the exact point in the video where the orientation time occurred.

链接地址: http://www.djcxy.com/p/46498.html

上一篇: 在屏幕方向更改后填充

下一篇: 在Android中,Activity没有看到方向改变?