|
@@ -8,11 +8,8 @@ import org.yczbj.ycvideoplayerlib.config.ConstantKeys;
|
|
|
public class MeasureHelper {
|
|
|
|
|
|
private int mVideoWidth;
|
|
|
-
|
|
|
private int mVideoHeight;
|
|
|
-
|
|
|
private int mCurrentScreenScale;
|
|
|
-
|
|
|
private int mVideoRotationDegree;
|
|
|
|
|
|
public void setVideoRotation(int videoRotationDegree) {
|
|
@@ -30,9 +27,11 @@ public class MeasureHelper {
|
|
|
|
|
|
/**
|
|
|
* 注意:VideoView的宽高一定要定死,否者以下算法不成立
|
|
|
+ * 借鉴于网络
|
|
|
*/
|
|
|
public int[] doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
- if (mVideoRotationDegree == 90 || mVideoRotationDegree == 270) { // 软解码时处理旋转信息,交换宽高
|
|
|
+ if (mVideoRotationDegree == 90 || mVideoRotationDegree == 270) {
|
|
|
+ // 软解码时处理旋转信息,交换宽高
|
|
|
widthMeasureSpec = widthMeasureSpec + heightMeasureSpec;
|
|
|
heightMeasureSpec = widthMeasureSpec - heightMeasureSpec;
|
|
|
widthMeasureSpec = widthMeasureSpec - heightMeasureSpec;
|
|
@@ -47,6 +46,7 @@ public class MeasureHelper {
|
|
|
|
|
|
//如果设置了比例
|
|
|
switch (mCurrentScreenScale) {
|
|
|
+ //默认正常类型
|
|
|
case ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_DEFAULT:
|
|
|
default:
|
|
|
if (mVideoWidth * height < width * mVideoHeight) {
|
|
@@ -55,10 +55,12 @@ public class MeasureHelper {
|
|
|
height = width * mVideoHeight / mVideoWidth;
|
|
|
}
|
|
|
break;
|
|
|
+ //原始类型,指视频的原始类型
|
|
|
case ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_ORIGINAL:
|
|
|
width = mVideoWidth;
|
|
|
height = mVideoHeight;
|
|
|
break;
|
|
|
+ //16:9比例类型,最为常见
|
|
|
case ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_16_9:
|
|
|
if (height > width / 16 * 9) {
|
|
|
height = width / 16 * 9;
|
|
@@ -66,6 +68,7 @@ public class MeasureHelper {
|
|
|
width = height / 9 * 16;
|
|
|
}
|
|
|
break;
|
|
|
+ //4:3比例类型,也比较常见
|
|
|
case ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_4_3:
|
|
|
if (height > width / 4 * 3) {
|
|
|
height = width / 4 * 3;
|
|
@@ -73,10 +76,12 @@ public class MeasureHelper {
|
|
|
width = height / 3 * 4;
|
|
|
}
|
|
|
break;
|
|
|
+ //充满整个控件视图
|
|
|
case ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_MATCH_PARENT:
|
|
|
width = widthMeasureSpec;
|
|
|
height = heightMeasureSpec;
|
|
|
break;
|
|
|
+ //剧中裁剪类型
|
|
|
case ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_CENTER_CROP:
|
|
|
if (mVideoWidth * height > width * mVideoHeight) {
|
|
|
width = height * mVideoWidth / mVideoHeight;
|