android videoview屏幕缩放

xyang0917
博客专家认证
2012-11-05 04:35:53
请问如何实现视频按比例缩放:如4:3,16:9,原始大小、全屏播放等功能。网上很多有关视频缩放的资料大都是屏蔽VideoView类onMeasure方法中计算视频大小的代码,如下所示:

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//Log.i("@@@@", "onMeasure");
int width = getDefaultSize(mVideoWidth, widthMeasureSpec);
int height = getDefaultSize(mVideoHeight, heightMeasureSpec);
/*if (mVideoWidth > 0 && mVideoHeight > 0) {
if ( mVideoWidth * height > width * mVideoHeight ) {
//Log.i("@@@", "image too tall, correcting");
height = width * mVideoHeight / mVideoWidth;
} else if ( mVideoWidth * height < width * mVideoHeight ) {
//Log.i("@@@", "image too wide, correcting");
width = height * mVideoWidth / mVideoHeight;
} else {
//Log.i("@@@", "aspect ratio is correct: " +
//width+"/"+height+"="+
//mVideoWidth+"/"+mVideoHeight);
}
}*/
//Log.i("@@@@@@@@@@", "setting size: " + width + 'x' + height);
setMeasuredDimension(width, height);
}

然后通过LayoutParams对象改变VideoView的大小,但这种方法试过是不行的,只能缩小屏幕,而不能放大。目前网上有很多视频播放器都实现了相应的缩放功能,不知道他们是如何实现,求指导!
注:android版本2.3.1,设备是投影仪,底层驱动和平台接口有过修改。
...全文
877 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shexiangshun1 2014-12-17
  • 打赏
  • 举报
回复
楼主解答了吗?我这边也有同样的问题!
outspace_observer 2013-07-16
  • 打赏
  • 举报
回复
VideoView放到FrameLayout中试试
一只小爬虫 2013-05-07
  • 打赏
  • 举报
回复
我遇到了,需要求解啊
xyang0917 2012-11-06
  • 打赏
  • 举报
回复
这么不给力,自已顶!!难道这个问题无人遇到过吗?

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧