谷歌的Leanback 展示没有 ExoPlayer 的视频播放器
Google 的Leanback 展示带有 ExoPlayer 的视频播放器
我已经尝试过谷歌的 Leanback 展示,它也在“适合屏幕”模式下播放视频,两侧有黑条。我在 API 文档的任何地方都找不到更改缩放模式的选项
我必须查看VideoFragment
来源才能弄清楚这一点。VideoFragment
有一个简单的SurfaceView
作为其布局的根元素,您所要做的就是SurfaceView
匹配父级(即设备屏幕)的宽度和高度。为此,只需覆盖onVideoSizeChanged
并用于getSurfaceView
获取SurfaceView
对VideoFragment
.
@Override
protected void onVideoSizeChanged(int width, int height) {
switch (scaleMode) {
//Flag indicates that this video should stretch to screen
case MediaMetaData.SCALE_MODE_STRETCH:
View rootView = getView();
SurfaceView surfaceView = getSurfaceView();
ViewGroup.LayoutParams params = surfaceView.getLayoutParams();
params.height = rootView.getHeight();
params.width = rootView.getWidth();
surfaceView.setLayoutParams(params);
break;
//When the video shouldn't stretch, just invoke super to have the VideoFragment's default behavior which is fit to screen
default:
super.onVideoSizeChanged(width, height);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句