Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Dec 23, 2019
1 parent 5e5ae18 commit 5a56060
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,18 @@ protected void onCreate(Bundle savedInstanceState) {
//初始化不打开外部的旋转
orientationUtils.setEnable(false);

/**仅仅横屏旋转,不变直*/
orientationUtils.setOnlyRotateLand(true);

Map<String, String> header = new HashMap<>();
header.put("ee", "33");
header.put("allowCrossProtocolRedirects", "true");
GSYVideoOptionBuilder gsyVideoOption = new GSYVideoOptionBuilder();
gsyVideoOption.setThumbImageView(imageView)
.setIsTouchWiget(true)
.setRotateViewAuto(false)
//仅仅横屏旋转,不变直
.setOnlyRotateLand(true)
.setLockLand(false)
.setAutoFullWithSize(false)
.setShowFullAnimation(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public class GSYVideoOptionBuilder {
// 是否需要覆盖拓展类型
protected String mOverrideExtension;

private boolean mIsOnlyRotateLand = false;

//是否自定义的缓冲文件路径
protected File mCachePath;

Expand Down Expand Up @@ -539,6 +541,13 @@ public GSYVideoOptionBuilder setOverrideExtension(String overrideExtension) {
return this;
}


public GSYVideoOptionBuilder setOnlyRotateLand(boolean onlyRotateLand) {
this.mIsOnlyRotateLand = onlyRotateLand;
return this;
}


/**
* 在播放前才真正执行setup
* 目前弃用,请使用正常setup
Expand Down Expand Up @@ -615,6 +624,7 @@ public void build(GSYBaseVideoPlayer gsyVideoPlayer) {
gsyVideoPlayer.setOverrideExtension(mOverrideExtension);
gsyVideoPlayer.setAutoFullWithSize(mAutoFullWithSize);
gsyVideoPlayer.setRotateViewAuto(mRotateViewAuto);
gsyVideoPlayer.setOnlyRotateLand(mIsOnlyRotateLand);
gsyVideoPlayer.setLockLand(mLockLand);
gsyVideoPlayer.setSpeed(mSpeed, mSounchTouch);
gsyVideoPlayer.setHideKey(mHideKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class OrientationUtils {

private boolean mIsPause = false;

private boolean mIsOnlyRotateLand = false;

/**
* @param activity
* @param gsyVideoPlayer
Expand All @@ -44,13 +46,15 @@ public OrientationUtils(Activity activity, GSYBaseVideoPlayer gsyVideoPlayer) {
init();
}

private void init() {
protected void init() {
mOrientationEventListener = new OrientationEventListener(mActivity.getApplicationContext()) {
@Override
public void onOrientationChanged(int rotation) {
boolean autoRotateOn = (Settings.System.getInt(mActivity.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1);
if (!autoRotateOn && mRotateWithSystem) {
return;
if (!mIsOnlyRotateLand || getIsLand() == LAND_TYPE_NULL) {
return;
}
}
if (mVideoPlayer != null && mVideoPlayer.isVerticalFullByVideoSize()) {
return;
Expand All @@ -70,16 +74,18 @@ public void onOrientationChanged(int rotation) {
}
} else {
if (mIsLand > LAND_TYPE_NULL) {
mScreenType = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
if (mVideoPlayer.getFullscreenButton() != null) {
if (mVideoPlayer.isIfCurrentIsFullscreen()) {
mVideoPlayer.getFullscreenButton().setImageResource(mVideoPlayer.getShrinkImageRes());
} else {
mVideoPlayer.getFullscreenButton().setImageResource(mVideoPlayer.getEnlargeImageRes());
if (!mIsOnlyRotateLand) {
mScreenType = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
if (mVideoPlayer.getFullscreenButton() != null) {
if (mVideoPlayer.isIfCurrentIsFullscreen()) {
mVideoPlayer.getFullscreenButton().setImageResource(mVideoPlayer.getShrinkImageRes());
} else {
mVideoPlayer.getFullscreenButton().setImageResource(mVideoPlayer.getEnlargeImageRes());
}
}
mIsLand = LAND_TYPE_NULL;
}
mIsLand = LAND_TYPE_NULL;
mClick = false;
}
}
Expand Down Expand Up @@ -141,7 +147,7 @@ public void resolveByClick() {
mClick = true;
if (mIsLand == LAND_TYPE_NULL) {
int request = mActivity.getRequestedOrientation();
if(request == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
if (request == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
mScreenType = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
} else {
mScreenType = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
Expand Down Expand Up @@ -250,6 +256,17 @@ public boolean isRotateWithSystem() {
return mRotateWithSystem;
}

public boolean isOnlyRotateLand() {
return mIsOnlyRotateLand;
}

/**
* 旋转时仅处理横屏
*/
public void setOnlyRotateLand(boolean onlyRotateLand) {
this.mIsOnlyRotateLand = onlyRotateLand;
}

/**
* 是否更新系统旋转,false的话,系统禁止旋转也会跟着旋转
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public abstract class GSYBaseVideoPlayer extends GSYVideoControlView {
//旋转工具类
protected OrientationUtils mOrientationUtils;

private boolean mIsOnlyRotateLand = false;
//全屏返回监听,如果设置了,默认返回无效
protected View.OnClickListener mBackFromFullScreenListener;
protected Handler mInnerHandler = new Handler();
Expand Down Expand Up @@ -313,6 +314,7 @@ protected void resolveFullVideoShow(Context context, final GSYBaseVideoPlayer gs
mOrientationUtils = new OrientationUtils((Activity) context, gsyVideoPlayer);
mOrientationUtils.setEnable(isRotateViewAuto());
mOrientationUtils.setRotateWithSystem(mRotateWithSystem);
mOrientationUtils.setOnlyRotateLand(mIsOnlyRotateLand);
gsyVideoPlayer.mOrientationUtils = mOrientationUtils;

final boolean isVertical = isVerticalFullByVideoSize();
Expand Down Expand Up @@ -865,6 +867,9 @@ public boolean isRotateWithSystem() {
*/
public void setRotateWithSystem(boolean rotateWithSystem) {
this.mRotateWithSystem = rotateWithSystem;
if (mOrientationUtils != null) {
mOrientationUtils.setRotateWithSystem(rotateWithSystem);
}
}

/**
Expand Down Expand Up @@ -971,6 +976,20 @@ public void setNeedAutoAdaptation(boolean needAutoAdaptation) {
isNeedAutoAdaptation = needAutoAdaptation;
}

public boolean isOnlyRotateLand() {
return mIsOnlyRotateLand;
}

/**
* 旋转时仅处理横屏
*/
public void setOnlyRotateLand(boolean onlyRotateLand) {
this.mIsOnlyRotateLand = onlyRotateLand;
if (mOrientationUtils != null) {
mOrientationUtils.setOnlyRotateLand(mIsOnlyRotateLand);
}
}

/**
* 检测是否根据视频尺寸,自动选择竖屏全屏或者横屏全屏;
* 并且适配在竖屏横屏时,由于刘海屏或者打孔屏占据空间,导致标题显示被遮盖的问题
Expand Down
16 changes: 8 additions & 8 deletions gsyVideoPlayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

//api project(':gsyVideoPlayer-java')
api project(':gsyVideoPlayer-java')
//api project(':gsyVideoPlayer-exo_player2')
//api project(':gsyVideoPlayer-armv5')
//api project(':gsyVideoPlayer-armv7a')
Expand All @@ -48,16 +48,16 @@ dependencies {

//api "com.shuyu:GSYVideoPlayer:$gsyVideoVersion"

api "com.shuyu:gsyVideoPlayer-java:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-java:$gsyVideoVersion"
api "com.shuyu:GSYVideoPlayer-exo2:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-armv5:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-armv7a:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-arm64:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-x64:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-x86:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-armv5:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-armv7a:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-arm64:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-x64:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-x86:$gsyVideoVersion"

//更多配置版so,增加了concat,rtsp,mpeg,crypto
//api "com.shuyu:gsyVideoPlayer-ex_so:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-ex_so:$gsyVideoVersion"

}

Expand Down

0 comments on commit 5a56060

Please sign in to comment.