1

I have an activity which should display a VideoView in landscape, but the activity itself must not be in landscape mode, so this is what i have.

    <activity
        android:name=".gui.VideoPlayer"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:screenOrientation="portrait" >
    </activity>

<?xml version="1.0" encoding="utf-8"?>

Activity

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <VideoView
        android:id="@+id/myvideoview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center" />

</LinearLayout>

(The activity itself must remain in portrait mode because the device will be put in a case which covers the navigation and statusbars, but in landscape mode it wont cover them any more)

Cœur
  • 37,241
  • 25
  • 195
  • 267
wutzebaer
  • 14,365
  • 19
  • 99
  • 170
  • 1
    I Think this [question][1] & this [answer][2] may answer your question. [1]: http://stackoverflow.com/q/4434027/2978334 [2]: http://stackoverflow.com/a/4452597/2978334 – Mycoola Dec 17 '14 at 12:48

1 Answers1

0

I know this is not the optimal answer but I had the same issue a while ago and found a pretty convenient workaround that might help you too.

Try to use a TextureView instead of VideoView because when you rotate it, the content inside rotates as well.

 <TextureView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/my_texture_view"
    android:rotation="90"
    android:scaleX="1.8"
    />

Next you'll have to create a SurfaceTextureListener and set it to your view like below:

 TextureView.SurfaceTextureListener mTextureListener = new TextureView.SurfaceTextureListener() {
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {

        Surface s = new Surface(surfaceTexture);
        try {
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(currentPageVideoUrl);
        mMediaPlayer.setSurface(s);
        mMediaPlayer.prepare();
        }catch (Exception e){e.printStackTrace();}
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) {
    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        return false;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {

    }
};

And now just set the listener to your TextureView:

 mTextureView.setSurfaceTextureListener(mTextureListener);

All that's left to do is to call this to start the video:

mMediaPlayer.start();

BONUS:If you want to make more complex adjustments like adjusting the video aspect ratio You can check this library for more details.

petrrr33
  • 583
  • 9
  • 24