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.

  • Computer Vision and AR libraries availabe for Android?
  • Whats is taco memory and why am I low on it?
  • Correct way of calling super.onStop() when unregistering a listener
  • Widget becomes invisible after reinstall
  • Android task and process, SingleTask and SingleInstance
  • show the information in the middle of the call
  • 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

    Related posts:

    GCM with PHP (Google Cloud Messaging)
    ADB No Devices Found
    What can be a cause of java.net.SocketException: recvfrom failed: ETIMEDOUT?
    Reboot/Power Off Android Emulator
    How to dismiss/close/collapse SearchView in ActionBar in MainActivity?
    What can I do about a privacy url?
  • SoftKeyboard hiding EditText
  • How can I filter ListView data when typing on EditText in android
  • What is the meaning of the log from tag:“szipinf” and text:“Initializing inflate state” from Logcat
  • How can I get the bitmap of the canvas I get in onDraw?
  • Intellij Android project schema URI not registered?
  • CollapsingToolbarLayout not shows Title
  • 2 Solutions collect form web for “Avoid Android VideoView corruption when rotating back to portrait”

    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

    From the source code AndroidManifest.xml


    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:

    public void onConfigurationChanged(Configuration 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:)

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

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.