我在我的应用中添加了ExoPlayer。
我将整个应用程序的屏幕方向固定为纵向。
我需要将 ExoPlayer 旋转到横向模式。
我该如何解决这个问题?
我只需要旋转 Exo 框架而不是整个片段或活动。
我将整个应用程序的屏幕方向固定为纵向。
我需要将 ExoPlayer 旋转到横向模式。
我该如何解决这个问题?
我只需要旋转 Exo 框架而不是整个片段或活动。
app:surface_type="texture_view"
。android:rotation="90"
设置到您的布局中,或者在 Kotlin 中调用 playerView.rotation = 90f
。设置 app:surface_type="texture_view"
对于旋转是必须的。 - Albert Vila CalvoexoPlayerView.getVideoSurfaceView().setRotation(90);
((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
当想要旋转回纵向时
((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
您不需要额外的库来实现这一点,只需设置 app:surface_type="texture_view"
,然后您就可以在xml中使用 android:rotation="39"
或者在代码中使用 mainVideoView.rotation = 39f
来旋转 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" />