谷歌没有ExoPlayer的Leanback showcase视频播放器
谷歌的Leanback showcase视频播放器与ExoPlayer
我已经尝试了谷歌的leanback展示,它也在“适合屏幕”模式下播放视频,两侧有黑条。我无法在API文档的任何位置找到更改缩放模式的选项
我不得不调查VideoFragment
来源来解决这个问题。 VideoFragment
有一个简单的SurfaceView
作为其布局的根元素,你所要做的就是让SurfaceView
与父级(即设备屏幕)的宽度和高度相匹配。要做到这一点,只需覆盖onVideoSizeChanged
并使用getSurfaceView
来获取对SurfaceView
中使用的package-private 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);
}
}