Android 中 ExoPlayer 播放器裁剪显示
根据需求,因为分辨率不同的缘故,需要视频居中显示,如果四周超出则裁剪显示,开始时使用 setVideoScalingMode() 方法,并未生效。如下:
mPlayer.setVideoScalingMode(VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
网上搜索到一个可用的方案如下:
Java 或 Kotlin
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
XML
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:resize_mode="zoom"/>