代码之家  ›  专栏  ›  技术社区  ›  PrashanD

如何在使用视频片段在Leanback上播放视频时将缩放模式设置为全屏

  •  0
  • PrashanD  · 技术社区  · 6 年前

    Leanback showcase 不带ExoPlayer的视频播放器

    谷歌的 Leanback showcase

    我试过谷歌的倾斜展示,它也在“适合屏幕”模式下播放视频,旁边有黑条。我也找不到在API文档上更改scale模式的选项

    0 回复  |  直到 6 年前
        1
  •  0
  •   PrashanD    6 年前

    我得调查一下 VideoFragment 想办法解决这个问题。 视频片段 有一个简单的 SurfaceView 作为其布局的根元素,您所要做的就是 表面视图 匹配父级(即设备屏幕)的宽度和高度。这样做只是超越 onVideoSizeChanged getSurfaceView 获取对包private的引用 表面视图 中使用的实例 视频片段 .

    @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);
        }
    }