提交 18576d6c 编写于 作者: G guoshuyu

优化 ijk 模式的视频尺寸计算

上级 d9e82c56
......@@ -254,12 +254,12 @@ public class DetailPlayer extends AppCompatActivity {
private String getUrl() {
///String url = "android.resource://" + getPackageName() + "/" + R.raw.test1;
//String url = "android.resource://" + getPackageName() + "/" + R.raw.test1;
//注意,用ijk模式播放raw视频,这个必须打开
///GSYVideoManager.instance().enableRawPlay(getApplicationContext());
//GSYVideoManager.instance().enableRawPlay(getApplicationContext());
///exo raw 支持
///String url = RawResourceDataSource.buildRawResourceUri(R.raw.test).toString();
//String url = RawResourceDataSource.buildRawResourceUri(R.raw.test).toString();
//断网自动重新链接,url前接上ijkhttphook:
//String url = "ijkhttphook:https://res.exexm.com/cw_145225549855002";
......@@ -302,6 +302,7 @@ public class DetailPlayer extends AppCompatActivity {
//String url = "http://hls.ciguang.tv/hdtv/video.m3u8";
//String url = "https://res.exexm.com/cw_145225549855002";
//String url = "http://storage.gzstv.net/uploads/media/huangmeiyan/jr05-09.mp4";//mepg
//String url = "https://zh-files.oss-cn-qingdao.aliyuncs.com/20170808223928mJ1P3n57.mp4";//90度
return url;
}
}
......@@ -87,12 +87,19 @@ public final class MeasureHelper {
heightMeasureSpec = tempSpec;
}
int width = View.getDefaultSize(mVideoWidth, widthMeasureSpec);
int realWidth = mVideoWidth;
if(mVideoSarNum != 0 && mVideoSarDen != 0) {
double pixelWidthHeightRatio = mVideoSarNum / (mVideoSarDen / 1.0);
realWidth = (int) (pixelWidthHeightRatio * mVideoWidth);
}
int width = View.getDefaultSize(realWidth, widthMeasureSpec);
int height = View.getDefaultSize(mVideoHeight, heightMeasureSpec);
if (mCurrentAspectRatio == GSYVideoType.SCREEN_MATCH_FULL) {
width = widthMeasureSpec;
height = heightMeasureSpec;
} else if (mVideoWidth > 0 && mVideoHeight > 0) {
} else if (realWidth > 0 && mVideoHeight > 0) {
int widthSpecMode = View.MeasureSpec.getMode(widthMeasureSpec);
int widthSpecSize = View.MeasureSpec.getSize(widthMeasureSpec);
int heightSpecMode = View.MeasureSpec.getMode(heightMeasureSpec);
......@@ -126,7 +133,7 @@ public final class MeasureHelper {
case GSYVideoType.SCREEN_TYPE_FULL:
//case GSYVideoType.AR_ASPECT_WRAP_CONTENT:
default:
displayAspectRatio = (float) mVideoWidth / (float) mVideoHeight;
displayAspectRatio = (float) realWidth / (float) mVideoHeight;
if (mVideoSarNum > 0 && mVideoSarDen > 0)
displayAspectRatio = displayAspectRatio * mVideoSarNum / mVideoSarDen;
break;
......@@ -164,7 +171,7 @@ public final class MeasureHelper {
default:
if (shouldBeWider) {
// too wide, fix width
width = Math.min(mVideoWidth, widthSpecSize);
width = Math.min(realWidth, widthSpecSize);
height = (int) (width / displayAspectRatio);
} else {
// too high, fix height
......@@ -179,17 +186,17 @@ public final class MeasureHelper {
height = heightSpecSize;
// for compatibility, we adjust size based on aspect ratio
if (mVideoWidth * height < width * mVideoHeight) {
if (realWidth * height < width * mVideoHeight) {
//Log.i("@@@", "image too wide, correcting");
width = height * mVideoWidth / mVideoHeight;
} else if (mVideoWidth * height > width * mVideoHeight) {
width = height * realWidth / mVideoHeight;
} else if (realWidth * height > width * mVideoHeight) {
//Log.i("@@@", "image too tall, correcting");
height = width * mVideoHeight / mVideoWidth;
height = width * mVideoHeight / realWidth;
}
} else if (widthSpecMode == View.MeasureSpec.EXACTLY) {
// only the width is fixed, adjust the height to match aspect ratio if possible
width = widthSpecSize;
height = width * mVideoHeight / mVideoWidth;
height = width * mVideoHeight / realWidth;
if (heightSpecMode == View.MeasureSpec.AT_MOST && height > heightSpecSize) {
// couldn't match aspect ratio within the constraints
height = heightSpecSize;
......@@ -197,24 +204,24 @@ public final class MeasureHelper {
} else if (heightSpecMode == View.MeasureSpec.EXACTLY) {
// only the height is fixed, adjust the width to match aspect ratio if possible
height = heightSpecSize;
width = height * mVideoWidth / mVideoHeight;
width = height * realWidth / mVideoHeight;
if (widthSpecMode == View.MeasureSpec.AT_MOST && width > widthSpecSize) {
// couldn't match aspect ratio within the constraints
width = widthSpecSize;
}
} else {
// neither the width nor the height are fixed, try to use actual video size
width = mVideoWidth;
width = realWidth;
height = mVideoHeight;
if (heightSpecMode == View.MeasureSpec.AT_MOST && height > heightSpecSize) {
// too tall, decrease both width and height
height = heightSpecSize;
width = height * mVideoWidth / mVideoHeight;
width = height * realWidth / mVideoHeight;
}
if (widthSpecMode == View.MeasureSpec.AT_MOST && width > widthSpecSize) {
// too wide, decrease both width and height
width = widthSpecSize;
height = width * mVideoHeight / mVideoWidth;
height = width * mVideoHeight / realWidth;
}
}
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册