Skip to content

Commit

Permalink
增加自定义显示比例的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Nov 11, 2019
1 parent 4944fa0 commit cac7ef7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.shuyu.gsyvideoplayer.player.IPlayerInitSuccessListener;
import com.shuyu.gsyvideoplayer.player.PlayerFactory;
import com.shuyu.gsyvideoplayer.utils.Debuger;
import com.shuyu.gsyvideoplayer.utils.GSYVideoType;
import com.squareup.leakcanary.LeakCanary;

import static com.google.android.exoplayer2.util.Util.inferContentType;
Expand Down Expand Up @@ -51,6 +52,9 @@ public void onCreate() {
//GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_FULL);
//GSYVideoType.setShowType(GSYVideoType.SCREEN_MATCH_FULL);

//GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_CUSTOM);
//GSYVideoType.setScreenScaleRatio(9.0f/16);

//GSYVideoType.setRenderType(GSYVideoType.SUFRACE);
//GSYVideoType.setRenderType(GSYVideoType.GLSURFACE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ public class GSYVideoType {
//4:3
public final static int SCREEN_TYPE_4_3 = 2;

//18:9
public final static int SCREEN_TYPE_18_9 = 6;

//全屏裁减显示,为了显示正常 CoverImageView 建议使用FrameLayout作为父布局
public final static int SCREEN_TYPE_FULL = 4;

//全屏拉伸显示,使用这个属性时,surface_container建议使用FrameLayout
public final static int SCREEN_MATCH_FULL = -4;

//自定义比例,需要设置 sScreenScaleRatio
public final static int SCREEN_TYPE_CUSTOM = -5;

/**
* 自定义的显示比例
*/
private static float sScreenScaleRatio = 0;

/**
* GLSurfaceView 主要用于OpenGL渲染的
*/
Expand Down Expand Up @@ -118,4 +129,15 @@ public static void setRenderType(int renderType) {
sRenderType = renderType;
}

public static float getScreenScaleRatio() {
return sScreenScaleRatio;
}

/***
* SCREEN_TYPE_CUSTOM 下自定义显示比例
* @param screenScaleRatio 高宽比,如 16:9
*/
public static void setScreenScaleRatio(float screenScaleRatio) {
GSYVideoType.sScreenScaleRatio = screenScaleRatio;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,21 @@ public void doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mVideoRotationDegree == 90 || mVideoRotationDegree == 270)
displayAspectRatio = 1.0f / displayAspectRatio;
break;
case GSYVideoType.SCREEN_TYPE_18_9:
displayAspectRatio = 18.0f / 9.0f;
if (mVideoRotationDegree == 90 || mVideoRotationDegree == 270)
displayAspectRatio = 1.0f / displayAspectRatio;
break;
case GSYVideoType.SCREEN_TYPE_4_3:
displayAspectRatio = 4.0f / 3.0f;
if (mVideoRotationDegree == 90 || mVideoRotationDegree == 270)
displayAspectRatio = 1.0f / displayAspectRatio;
break;
case GSYVideoType.SCREEN_TYPE_CUSTOM:
displayAspectRatio = GSYVideoType.getScreenScaleRatio();
if (mVideoRotationDegree == 90 || mVideoRotationDegree == 270)
displayAspectRatio = 1.0f / displayAspectRatio;
break;
case GSYVideoType.SCREEN_TYPE_DEFAULT:
case GSYVideoType.SCREEN_TYPE_FULL:
//case GSYVideoType.AR_ASPECT_WRAP_CONTENT:
Expand All @@ -121,6 +131,8 @@ public void doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
case GSYVideoType.SCREEN_TYPE_DEFAULT:
case GSYVideoType.SCREEN_TYPE_16_9:
case GSYVideoType.SCREEN_TYPE_4_3:
case GSYVideoType.SCREEN_TYPE_18_9:
case GSYVideoType.SCREEN_TYPE_CUSTOM:
if (shouldBeWider) {
// too wide, fix width
width = widthSpecSize;
Expand Down

0 comments on commit cac7ef7

Please sign in to comment.