在我的应用程序中,我使用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不仅旋转他自己的边界,而且旋转他的内容。
发布于 2018-03-27 08:04:04
将纹理视图用于曲面类型。默认情况下,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"
/>发布于 2019-07-22 11:53:10
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很快就会支持旋转预览视频
发布于 2017-06-15 19:30:13
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 player视图
app:controller_layout_id="@layout/your_layout"https://stackoverflow.com/questions/44564356
复制相似问题