diff --git a/app/src/main/java/com/example/gsyvideoplayer/DetailPlayer.java b/app/src/main/java/com/example/gsyvideoplayer/DetailPlayer.java index 85ed4d8c5..5bde7279e 100644 --- a/app/src/main/java/com/example/gsyvideoplayer/DetailPlayer.java +++ b/app/src/main/java/com/example/gsyvideoplayer/DetailPlayer.java @@ -97,6 +97,9 @@ protected void onCreate(Bundle savedInstanceState) { //初始化不打开外部的旋转 orientationUtils.setEnable(false); + /**仅仅横屏旋转,不变直*/ + orientationUtils.setOnlyRotateLand(true); + Map header = new HashMap<>(); header.put("ee", "33"); header.put("allowCrossProtocolRedirects", "true"); @@ -104,6 +107,8 @@ protected void onCreate(Bundle savedInstanceState) { gsyVideoOption.setThumbImageView(imageView) .setIsTouchWiget(true) .setRotateViewAuto(false) + //仅仅横屏旋转,不变直 + .setOnlyRotateLand(true) .setLockLand(false) .setAutoFullWithSize(false) .setShowFullAnimation(false) diff --git a/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/builder/GSYVideoOptionBuilder.java b/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/builder/GSYVideoOptionBuilder.java index e9915f6c5..1abbaafa3 100644 --- a/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/builder/GSYVideoOptionBuilder.java +++ b/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/builder/GSYVideoOptionBuilder.java @@ -125,6 +125,8 @@ public class GSYVideoOptionBuilder { // 是否需要覆盖拓展类型 protected String mOverrideExtension; + private boolean mIsOnlyRotateLand = false; + //是否自定义的缓冲文件路径 protected File mCachePath; @@ -539,6 +541,13 @@ public GSYVideoOptionBuilder setOverrideExtension(String overrideExtension) { return this; } + + public GSYVideoOptionBuilder setOnlyRotateLand(boolean onlyRotateLand) { + this.mIsOnlyRotateLand = onlyRotateLand; + return this; + } + + /** * 在播放前才真正执行setup * 目前弃用,请使用正常setup @@ -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); diff --git a/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/utils/OrientationUtils.java b/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/utils/OrientationUtils.java index 947100171..fa90baf6e 100644 --- a/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/utils/OrientationUtils.java +++ b/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/utils/OrientationUtils.java @@ -34,6 +34,8 @@ public class OrientationUtils { private boolean mIsPause = false; + private boolean mIsOnlyRotateLand = false; + /** * @param activity * @param gsyVideoPlayer @@ -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; @@ -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; } } @@ -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; @@ -250,6 +256,17 @@ public boolean isRotateWithSystem() { return mRotateWithSystem; } + public boolean isOnlyRotateLand() { + return mIsOnlyRotateLand; + } + + /** + * 旋转时仅处理横屏 + */ + public void setOnlyRotateLand(boolean onlyRotateLand) { + this.mIsOnlyRotateLand = onlyRotateLand; + } + /** * 是否更新系统旋转,false的话,系统禁止旋转也会跟着旋转 * diff --git a/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYBaseVideoPlayer.java b/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYBaseVideoPlayer.java index 024bbeec7..6b09727c4 100644 --- a/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYBaseVideoPlayer.java +++ b/gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYBaseVideoPlayer.java @@ -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(); @@ -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(); @@ -865,6 +867,9 @@ public boolean isRotateWithSystem() { */ public void setRotateWithSystem(boolean rotateWithSystem) { this.mRotateWithSystem = rotateWithSystem; + if (mOrientationUtils != null) { + mOrientationUtils.setRotateWithSystem(rotateWithSystem); + } } /** @@ -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); + } + } + /** * 检测是否根据视频尺寸,自动选择竖屏全屏或者横屏全屏; * 并且适配在竖屏横屏时,由于刘海屏或者打孔屏占据空间,导致标题显示被遮盖的问题 diff --git a/gsyVideoPlayer/build.gradle b/gsyVideoPlayer/build.gradle index 9da0cab07..9b6603b0c 100644 --- a/gsyVideoPlayer/build.gradle +++ b/gsyVideoPlayer/build.gradle @@ -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') @@ -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" }