[英]Rotating Exoplayer
I added exoplayer to my app.我将 exoplayer 添加到我的应用程序中。
I fixed the screen orientation to portrait for whole my app.我将整个应用程序的屏幕方向固定为纵向。
I need exoplayer to be rotated to landscape mode.我需要将 exoplayer 旋转到横向模式。
How can I handle this issue?我该如何处理这个问题?
I just need to rotate the exo frame and not the whole fragment or activity.我只需要旋转 exo 框架而不是整个片段或活动。
您可以使用https://github.com/rongi/rotate-layout绘制旋转的 ExoPlayer 内容,但要使该库工作,您必须在 PlayerView 中使用app:surface_type="texture_view"
This can be done by simple two lines of code,这可以通过简单的两行代码来完成,
When you click any button and want to rotate to LANDSCAPE当您单击任何按钮并想要旋转到 LANDSCAPE 时
((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
And when wanna rotate back to PORTRAIT当想旋转回肖像时
((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
exoPlayerView.getVideoSurfaceView().setRotation(90);
You dont need extra library to do so, simply set app:surface_type="texture_view"
and then you can rotate texture_view
in xml using android:rotation="39"
or in code using mainVideoView.rotation = 39f
:您不需要额外的库来执行此操作,只需设置
app:surface_type="texture_view"
,然后您可以使用android:rotation="39"
或使用mainVideoView.rotation = 39f
在代码中android:rotation="39"
xml 中的texture_view
:
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/mainVideoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:focusable="true"
android:nextFocusLeft="@id/resizeLeft"
android:nextFocusRight="@id/resizeRight"
android:nextFocusUp="@+id/mediaContainer"
android:nextFocusDown="@+id/exo_pause"
app:surface_type="texture_view"
android:rotation="39"
app:controller_layout_id="@layout/custom_playback_control" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.