您的位置:首页 > 移动开发 > Android开发

Android 百度云媒体 等播放器播放4:3等多种比例的视频 大小配置的问题

2016-11-07 11:12 435 查看
视频播放宽度大小各不一样,就需要根据视频的尺寸去适应屏幕的宽度和高度进行缩放。

思路是在onPrepared方法中,或者切换屏幕后,获取video的高度和宽度。以及屏幕展示区域的高度的宽度。并对比二者比例,进行缩放。

简单的代码如下,仅供参考

WindowManager wm = (WindowManager) MovieOverViewActivity.this
.getSystemService(Context.WINDOW_SERVICE);
Rect outRect = new Rect();
MovieOverViewActivity.this.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(outRect);
int width = wm.getDefaultDisplay().getWidth()-outRect.top;
int height = wm.getDefaultDisplay().getHeight();
int mVideoWidth = mVV.getVideoWidth();
int mVideoHeight = mVV.getVideoHeight();
RelativeLayout.LayoutParams layoutParams=(RelativeLayout.LayoutParams)mVV.getLayoutParams();
if(mVideoWidth>0&&mVideoHeight>0){
Log.d("宽度,",width+":"+height+":"+mVideoWidth+":"+mVideoHeight);
if(width*mVideoHeight>height*mVideoWidth){
width = height * mVideoWidth / mVideoHeight;
}else if(mVideoWidth * height < width * mVideoHeight){
height = width * mVideoHeight / mVideoWidth;
}
}
layoutParams.height = height;
layoutParams.width = width;
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
// layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
// layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
// layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
// layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

mVV.setLayoutParams(layoutParams);//mvv 为BVideoView
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐