Avoid Android VideoView corruption when rotating back to portrait

拈花ヽ惹草 提交于 2019-11-27 08:29:00

In the source code at https://github.com/gradha/Android-video-stream-rotation. you added the comment:

Since we specified in the AndroidManifest.xml that we want to handle our own orientation changes, we resize the screen in function of being portrait or landscape.

From the source code AndroidManifest.xml

android:configChanges="orientation|screenSize"

So, if you add this attribute to the activity element in the manifest, I would interpret that as the activity will handle all the orientation changes? not you?

From Android Developers

To declare that your activity handles a configuration change, edit the appropriate activity element in your manifest file to include the android:configChanges attribute... more

So you should not need to:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

I created a test project to check if this was the case:

Rotating Video Stream Example: https://github.com/TouchBoarder/RotatingVideoStream

My conclusion: I did not need to overide the "onConfigurationChanged" in the activity to display the video correct in both portrait and landscape, and the video keeps playing on rotation changes.

Feel free to improve and use the code:)

Grzegorz Adam Hankiewicz

Turns out my whole test case was wrong. Right up until the commit where I blame the easy videoview example on being wrong everything was according to the book. However I forgot the android:configChanges="orientation" line, and adding this line on top of the previously mentioned commit makes everything work without video corruption.

I'll be marking hsigmond's answer as valid for providing a test example I could compare to and find out the true problem. My whole working around this with custom orientation handlers and a subclass of the VideoView was wrong and incorrectly based on the question Android VideoView orientation change with buffered video. Not that that is wrong, I simply applied it incorrectly (plus other answers there also mentioned the missing android:configChanges).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!