Alex Ross
Alex Ross

Reputation: 3839

Android VideoView not playing after setRotation()

I've found that after calling setRotation() on a VideoView, that VideoView no longer plays. No errors are thrown by the Android runtime, and the VideoView correctly determines its crop dimensions but only shows as a solid black box.

Is this a known limitation? If so is there another way to rotate VideoViews? I'm using API level 16.

Edit: The video plays audio, but no video. Perhaps the underlying SurfaceView isn't being repositioned?

Upvotes: 2

Views: 1734

Answers (1)

Alex Ross
Alex Ross

Reputation: 3839

To answer myself in case it helps somebody later, this is a known limitation of VideoView. Quote from this Android graphics blog post:

Because a SurfaceView’s content does not live in the application’s window, it cannot be transformed (moved, scaled, rotated) efficiently. This makes it difficult to use a SurfaceView inside a ListView or a ScrollView. SurfaceView also cannot interact properly with some features of the UI toolkit such as fading edges or View.setAlpha().

The only solution I could find was to replace the VideoView with the newly-introduced TextureView, which is only available in API level 14 and above. From what I read it is not currently available in the compatibility library. This question has an example of how to use a TextureView to play video, it's pretty easy and all you lose is the convenience of a VideoView wrapping a MediaPlayer for you.

Upvotes: 1

Related Questions