使用VideoFragment在Leanback上播放视频时,如何将缩放模式设置为拉伸到全屏

问题描述 投票:0回答:1

谷歌没有ExoPlayer的Leanback showcase视频播放器

谷歌的Leanback showcase视频播放器与ExoPlayer

我已经尝试了谷歌的leanback展示,它也在“适合屏幕”模式下播放视频,两侧有黑条。我无法在API文档的任何位置找到更改缩放模式的选项

android android-tv leanback
1个回答
0
投票

我不得不调查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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.