如何在 ExoPlayer-V2 中缩放视频 - 全屏播放视频
How can I scale video in ExoPlayer-V2 - Play Video In Full Screen
我正在 Exoplayer
上播放来自 URL
的视频,它使用 resize_mode
拉伸 resizing/on 上的视频,正如我在布局文件中提到的那样 我不是能够保持视频的纵横比。
我想像 image2 中提到的那样像 TextureSurface
中那样做刻度类型 CENTER_CROP
但我得到的输出是 图片1
我试过下面的例子
我的输出 (Img 1) 和预期输出 (Img 2)
exoplayer layout code
<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:resize_mode="fill"
它适合屏幕中的视频但垂直拉伸,
那么我该如何解决这个问题。
以下两行帮助我在 full-screen 模式下播放视频。
在布局文件中使用 app:resize_mode
这在某种程度上有所帮助,但它会像问题图片中提到的那样拉伸视频。
<com.google.android.exoplayer2.ui.PlayerView
android:layout_width="match_parent"
app:resize_mode="...."
android:layout_height="match_parent" />
尝试根据您的要求将 AspectRatioFrameLayout
更改为 FILL,FIT,ZOOM...
,更改以下行对我有用。
exoVideoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
下一行将确保即使 4:3 个视频也能正确保持纵横比。
exoPlayer.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
您也可以尝试在 exoplayer
中更改 VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
为了在 exo 播放器中保持中心裁剪,下面的代码对我有用:
Java代码:
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
或者您可以使用来自 xml:
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
app:resize_mode="zoom"
android:layout_height="match_parent" />
以下是可以使用的调整大小模式选项
app:resize_mode="fixed_width"
app:resize_mode="fixed_height"
app:resize_mode="fill"
app:resize_mode="fit"
app:resize_mode="zoom"
您可以尝试每一种,看看它对您容器的影响。
我的问题已通过以下几行解决:
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
exoPlayer.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
我正在 Exoplayer
上播放来自 URL
的视频,它使用 resize_mode
拉伸 resizing/on 上的视频,正如我在布局文件中提到的那样 我不是能够保持视频的纵横比。
我想像 image2 中提到的那样像 TextureSurface
中那样做刻度类型 CENTER_CROP
但我得到的输出是 图片1
我试过下面的例子
我的输出 (Img 1) 和预期输出 (Img 2)
exoplayer layout code
<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:resize_mode="fill"
它适合屏幕中的视频但垂直拉伸,
那么我该如何解决这个问题。
以下两行帮助我在 full-screen 模式下播放视频。
在布局文件中使用 app:resize_mode
这在某种程度上有所帮助,但它会像问题图片中提到的那样拉伸视频。
<com.google.android.exoplayer2.ui.PlayerView
android:layout_width="match_parent"
app:resize_mode="...."
android:layout_height="match_parent" />
尝试根据您的要求将 AspectRatioFrameLayout
更改为 FILL,FIT,ZOOM...
,更改以下行对我有用。
exoVideoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
下一行将确保即使 4:3 个视频也能正确保持纵横比。
exoPlayer.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
您也可以尝试在 exoplayer
VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
为了在 exo 播放器中保持中心裁剪,下面的代码对我有用:
Java代码:
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
或者您可以使用来自 xml:
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
app:resize_mode="zoom"
android:layout_height="match_parent" />
以下是可以使用的调整大小模式选项
app:resize_mode="fixed_width"
app:resize_mode="fixed_height"
app:resize_mode="fill"
app:resize_mode="fit"
app:resize_mode="zoom"
您可以尝试每一种,看看它对您容器的影响。
我的问题已通过以下几行解决:
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
exoPlayer.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);