Avoid distorting Android VideoView when turning back to portrait

I managed to write a limited video player capable of viewing a .3gp file from the Internet. The video will be centered in full screen mode, maintaining the aspect ratio of the video. In addition, the rotation does not interrupt the video, which continues to play without problems.

Everything seems beautiful, but ... on my HTC Legend, when you rotate back to the portrait, the video is damaged, and instead of showing the full screen, it is displayed in its own pixel size. But again he turns to landscape work and manifests itself perfectly. Any ideas why? Unfortunately, I have no more hardware to test this, and I have run out of ideas for testing.

You can get the full source code of the example from https://github.com/gradha/Android-video-stream-rotation . It shows screenshots that open the application, rotate to landscape, touch the screen to display video controls, and then rotate back to portrait to see the damage. video started ok in portrait

on landscape the video works fine too

but now going back to portrait always shows corruption

+8
android corruption videoview screen-rotation
Jun 29 '11 at 17:14
source share
2 answers

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

Since we specified in AndroidManifest.xml in which we want to process our own change orientation, we change the screen size depending on the landscape.

From AndroidManifest.xml source code

android:configChanges="orientation|screenSize" 

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

From Android Developers

To declare that your team is handling a configuration change, edit the corresponding activity item in your manifest file to include the android: configChanges attribute ... more

Therefore, you need not :

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

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

Video stream rotation Example: https://github.com/TouchBoarder/RotatingVideoStream

My conclusion: I did not need to override "onConfigurationChanged" in action in order to display the video correctly in both portrait and landscape orientation, and the video continues to play with rotation changes.

Feel free to improve and use the code :)

+2
04 Oct '12 at 22:12
source share

Turns out my whole test case was wrong. Until commit, where I blame a simple example of a video image that you are wrong , everything was in accordance with the book. However, I forgot the android:configChanges="orientation" , and adding this line on top of the previously mentioned commit does everything without damaging the video.

I will mark hsigmond's answer as valid to provide a test case with which I could compare and find out the true problem. All my work around this with custom orientation handlers and a subclass of VideoView was incorrect and incorrectly based on the issue of changing the orientation of an Android VideoView with buffered video . Not that it was wrong, I just applied it incorrectly (plus other answers there also mentioned the missing android:configChanges ).

0
Jan 13 '13 at 17:59
source share



All Articles