Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

Avoid Android VideoView corruption when rotating back to portrait

I've managed to write a limited video player able to view a .3gp file from internet. The video will be shown centered full screen, maintaining the video aspect ratio. Also, rotations don't interrupt the video, which keeps playing without problems.

Everything seems fine, but... on my HTC Legend when you rotate back to portrait, the video is corrupted, and instead of showing full screen it is displayed at its native pixel size. But rotating again to landscape works and is shown perfectly. Any ideas why? Unfortunately I don't have more hardware to test this on and I've run out of ideas to test.

You can get the full example source code from https://github.com/gradha/Android-video-stream-rotation. Here are screen captures of me opening the application, rotating to landscape, touching the screen to display the video controls, then rotating back to portrait to see the corruption. video started ok in portrait

on landscape the video works fine too

but now going back to portrait always shows corruption

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...