android - 使用 VideoFragment 在 Leanback 上播放视频时如何将缩放模式设置为拉伸到全屏
问题描述
没有 ExoPlayer的 Google 的Leanback 展示视频播放器
带有 ExoPlayer的 Google Leanback 展示视频播放器
我已经试用了谷歌的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);
}
}
推荐阅读
- prolog - 绘制星星 Prolog 最多 N:画一条线太少了
- javascript - UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value "login" (type string) at path "_id" for model "User"
- python - Sublime Text 和 Anaconda 的自动补全功能不适用于本地项目目录中的代码
- hibernate - 使用 JPARepository 或 CRUDRepository 休眠(没有 Spring)
- c# - 在不中断授权流程的情况下替换 OpenIdConnectOptions 配置中的发现文档端点(OpenID Connect .Net Core 3.1)
- javascript - 如何在javascript中向后移动画布?
- excel - 我的 For 循环没有删除我想要的所有行(VBA)
- flutter - 如何在手机后退按钮按下时最小化全屏 Flutter Youtube Player?
- javascript - 未在嵌套的 js 反应中初始化变量
- snowflake-cloud-data-platform - 雪花 UDF (SQL) + FLATTEN 表在里面。无法评估不受支持的子查询类型