1

In my application, I show the video with google Exoplayer.
I am trying to solve a task: enter the full screen.
To achieve my objective, I rotate my ExoPlayer by N degrees.

<com.google.android.exoplayer2.ui.SimpleExoPlayerView
                android:id="@+id/player_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:rotation="32.342532532523"
                app:controller_layout_id="@layout/playback_control_view"
                app:resize_mode="fill" />

But with this rotation property only SimpleExoPlayerView is rotated, but not the video inside. Just like that: enter image description here

My question is how to force Exoplayer to rotate not only his own bounds but his contents too.

Ahmed Alnabhan
  • 608
  • 1
  • 9
  • 13
P. Ilyin
  • 761
  • 10
  • 28

3 Answers3

3

Use a texture view for the surface type. By default, ExoPlayerView uses a SurfaceView for its underlying implementation, which won't work in this case.

        <com.google.android.exoplayer2.ui.SimpleExoPlayerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:rotation="32.342532532523"
            app:surface_type="texture_view"
            />
David Liu
  • 9,426
  • 5
  • 40
  • 63
0

exoplay don't support rotate but you can use trick: solution one : rotate view solution two : rotate by matrix of texture view. I'm use solution two but had some problem when you rotate success texture not update render frame you must run video for update new rotate. my code for preview rotate video before edit:

 @Override
public void onAspectRatioUpdated(float targetAspectRatio, float naturalAspectRatio, boolean aspectRatioMismatch) {
    new Handler(Looper.getMainLooper()).post(() -> {
        TextureView textureView = (TextureView) getPlayerView().getVideoSurfaceView();
        textureView.setVisibility(View.INVISIBLE);
        applyTextureViewRotation(textureView, mPresenter.getRotation());
        textureView.setVisibility(View.VISIBLE);
        mPresenter.checkPlayAgain();
    });
}
public void checkPlayAgain() {
    if (mPlayer == null) {
        isResume = false;
        return;
    }
    if (isResume) {
        mPlayer.seekTo(cachePos);
        mPlayer.setPlayWhenReady(true);
    } else {
        mPlayer.seekTo(cachePos + 100);
        mPlayer.seekTo(cachePos - 100);
    }
}
public static void applyTextureViewRotation(TextureView textureView, int textureViewRotation) {
    float textureViewWidth = textureView.getWidth();
    float textureViewHeight = textureView.getHeight();
    if (textureViewWidth == 0 || textureViewHeight == 0 || textureViewRotation == 0) {
        textureView.setTransform(null);
    } else {
        Matrix transformMatrix = new Matrix();
        float pivotX = textureViewWidth / 2;
        float pivotY = textureViewHeight / 2;
        transformMatrix.postRotate(textureViewRotation, pivotX, pivotY);

        // After rotation, scale the rotated texture to fit the TextureView size.
        RectF originalTextureRect = new RectF(0, 0, textureViewWidth, textureViewHeight);
        RectF rotatedTextureRect = new RectF();
        transformMatrix.mapRect(rotatedTextureRect, originalTextureRect);
        transformMatrix.postScale(
                textureViewWidth / rotatedTextureRect.width(),
                textureViewHeight / rotatedTextureRect.height(),
                pivotX,
                pivotY);
        textureView.setTransform(transformMatrix);
    }
}

i just need change ratio of AspectRatioFrameLayout from port to land, hope it can help you. applyTextureViewRotation is private funtion of exo you can find it in source project exo. Maybe exoplayer will support rotate preview video soon

van nguyen
  • 21
  • 4
-4

Exo player auto manage the rotation. You just have to use SimpleExoPlayerView :

<com.google.android.exoplayer2.ui.SimpleExoPlayerView 
        android:id="@+id/player_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:resize_mode="fill"/>

You can customize the Exo player view using app:controller_layout_id:

app:controller_layout_id="@layout/your_layout"
SANAT
  • 8,489
  • 55
  • 66
  • Did you read my question? All your suggestions are already implemented in my sample – P. Ilyin Jun 16 '17 at 07:10
  • Exo player auto maintain screen orientation. why you are doing manually rotation? – SANAT Jun 16 '17 at 07:40
  • 6
    I need to do it mannualy because project which I develop was written by complete assholes who know nothing about architecture – P. Ilyin Jun 16 '17 at 07:58
  • no this will not work for rotating exoplayer , its related to controller and not the actual player – 1234567 Oct 31 '17 at 04:48