Android 在安卓系统中,使用exoplayer,如何用与设备不具有相同纵横比的视频填充surfaceview?
我有一个使用ExoPlayer播放视频的活动。当我全屏显示时,除非设备的纵横比等于视频的纵横比,否则我会在视频的顶部和底部看到小黑条 以下是布局的外观:Android 在安卓系统中,使用exoplayer,如何用与设备不具有相同纵横比的视频填充surfaceview?,android,video,fullscreen,exoplayer,Android,Video,Fullscreen,Exoplayer,我有一个使用ExoPlayer播放视频的活动。当我全屏显示时,除非设备的纵横比等于视频的纵横比,否则我会在视频的顶部和底部看到小黑条 以下是布局的外观: <com.google.android.exoplayer.AspectRatioFrameLayout android:id="@+id/video_frame" android:layout_width="match_parent" android:layout_height="wrap_content"
<com.google.android.exoplayer.AspectRatioFrameLayout
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true">
<SurfaceView android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"/>
<View android:id="@+id/shutter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"/>
</com.google.android.exoplayer.AspectRatioFrameLayout>
我可以解决这个问题,但我没有成功。
有没有办法让屏幕充满视频,即使部分视频从屏幕上被切断?您可以删除
com.google.android.exoplayer.AspectRatioFrameLayout
接下来,放置一个简单的FrameLayout
,其宽度和高度在匹配\u parent
上
请注意,SurfaceView
应保持宽度和高度=match\u parent
说明:
AspectRatioFrameLayout
根据实际视频比率(基于宽度、高度和像素比率计算)设置正确的视图高度。如果您不想这样做,Exoplayer仍然可以像以前一样在SurfaceView
上显示视图。如果SurfaceView
不是@Override
,它将没有纵横比 有一种用视频填充屏幕的最快方法。
转到SimpleExoPlayerView.java
类,将resizeMode
从AspectRatioFrameLayout.RESIZE\u MODE\u FIT
更改为AspectRatioFrameLayout.RESIZE\u MODE\u FILL
。
RESIZE\u MODE\u FILL
将忽略指定的纵横比。
如果在项目中使用ExoPlayer作为模块,请使用这种方式
已更新
如果将ExoPlayer用作库,则它们有一个方法来setResizeMode()
。
您只需将视图设置为AspectRatioFrameLayout.RESIZE\u MODE\u FILL
:
simpleExoPlayerView.setResizeMode(AspectRateLayout.RESIZE\u MODE\u FILL)
就这些 如果使用
SimpleExoPlayerView
,这也可以在XML中完成
只需添加app:resize\u mode=“zoom”
以保持视频的纵横比,或者app:resize\u mode=“fill”
如果您不关心纵横比的话
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:resize_mode="zoom" />
只需在xml中使用以下行即可。它会很好地工作
app:resize_mode="fill"
非常感谢。很抱歉回复太晚了…它起作用了!如此简单,只需更改为框架布局,就可以完成以下操作:impleeXoplayerView.setResizeMode(AspectRateOfRameLayout.RESIZE_MODE_FILL);它有助于用播放器填充父视图。如果我想设置纵横比呢?如果你想保持视频的纵横比,但将其扩展到全视图大小,如果你的视频比宽(纵向)高,则使用固定宽度;如果比高(横向)宽,则使用固定高度。不推荐使用它,现在有什么解决方案?晚会晚了,另一方面:如何确保
SurfaceView
+AspectRatioFrameLayout
保持正确的纵横比,并尽可能填充屏幕高度和/或宽度?您是否在SurfaceView
和。。。AspectRatioFrameLayout
上有什么?我的com.google.android.exoplayer2.ui.PlayerView上也有resize\u mode
标签。目前为止最简单的解决方案+1.
app:resize_mode="fill"