1

在我的应用程序中,我使用 google Exoplayer 显示视频。
我正在尝试解决一个任务:进入全屏。
为了实现我的目标,我将 ExoPlayer 旋转 N 度。

<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" />

但是有了这个rotation属性,只有 SimpleExoPlayerView 被旋转,而不是里面的视频。就像这样: 在此处输入图像描述

我的问题是如何强制 Exoplayer 不仅旋转他自己的边界,还旋转他的内容。

4

3 回答 3

3

为表面类型使用纹理视图。默认情况下,ExoPlayerView 使用 SurfaceView 作为其底层实现,在这种情况下将不起作用。

        <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"
            />
于 2018-03-27T00:04:04.493 回答
0

exoplay 不支持旋转,但您可以使用技巧: 解决方案一:旋转视图 解决方案二:按纹理视图矩阵旋转。我正在使用解决方案二,但是当您旋转成功纹理而不更新渲染帧时遇到了一些问题,您必须运行视频以更新新旋转。我的代码在编辑前预览旋转视频:

 @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);
    }
}

我只需要改变 AspectRatioFrameLayout 从港口到陆地的比例,希望它可以帮助你。applyTextureViewRotation 是 exo 的私有函数,你可以在源项目 exo 中找到它。也许 exoplayer 很快就会支持旋转预览视频

于 2019-07-22T03:53:10.247 回答
-4

Exo 播放器自动管理轮换。你只需要使用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"/>

您可以使用以下方法自定义 Exo 播放器视图app:controller_layout_id

app:controller_layout_id="@layout/your_layout"
于 2017-06-15T11:30:13.467 回答