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:
My question is how to force Exoplayer to rotate not only his own bounds but his contents too.
答案 0 :(得分: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"
/>
答案 1 :(得分: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将很快支持旋转预览视频
答案 2 :(得分:-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"/>
您可以使用app:controller_layout_id
自定义Exo播放器视图:
app:controller_layout_id="@layout/your_layout"