diff --git a/library/src/main/java/cn/jzvd/Jzvd.java b/library/src/main/java/cn/jzvd/Jzvd.java index 057d982c..99ad4c23 100644 --- a/library/src/main/java/cn/jzvd/Jzvd.java +++ b/library/src/main/java/cn/jzvd/Jzvd.java @@ -2,6 +2,7 @@ import android.content.Context; import android.content.pm.ActivityInfo; +import android.content.res.Configuration; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; @@ -67,6 +68,7 @@ public abstract class Jzvd extends FrameLayout implements View.OnClickListener, public static int ON_PLAY_PAUSE_TMP_STATE = 0;//这个考虑不放到库里,去自定义 public static int backUpBufferState = -1; public static float PROGRESS_DRAG_RATE = 1f;//进度条滑动阻尼系数 越大播放进度条滑动越慢 + boolean isVideoLandscape = true;//视频方向 public static AudioManager.OnAudioFocusChangeListener onAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {//是否新建个class,代码更规矩,并且变量的位置也很尴尬 @Override public void onAudioFocusChange(int focusChange) { @@ -429,6 +431,17 @@ protected void touchActionUp() { startProgressTimer(); } + public boolean isOrientationLandscape() { + if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + Log.i("info", "landscape"); // 横屏 + return true; + } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + Log.i("info", "portrait"); // 竖屏 + return false; + } + return true; + } + protected void touchActionMove(float x, float y) { Log.i(TAG, "onTouch surfaceContainer actionMove [" + this.hashCode() + "] "); float deltaX = x - mDownX; @@ -452,7 +465,7 @@ protected void touchActionMove(float x, float y) { } } else { //如果y轴滑动距离超过设置的处理范围,那么进行滑动事件处理 - if (mDownX < mScreenHeight * 0.5f) {//左侧改变亮度 + if (mDownX < (isOrientationLandscape() ? mScreenHeight * 0.5f : mScreenWidth * 0.5f)) {//左侧改变亮度 mChangeBrightness = true; WindowManager.LayoutParams lp = JZUtils.getWindow(getContext()).getAttributes(); if (lp.screenBrightness < 0) { @@ -845,6 +858,17 @@ public void onVideoSizeChanged(int width, int height) { } textureView.setVideoSize(width, height); } + setFullScreenOrientation(isVideoLandscape = width > height); + } + + private void setFullScreenOrientation(boolean isLandscape) { + + if (screen == SCREEN_FULLSCREEN) + if (isLandscape) { + JZUtils.setRequestedOrientation(jzvdContext, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } else { + JZUtils.setRequestedOrientation(jzvdContext, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } } public void startProgressTimer() { @@ -998,7 +1022,8 @@ public void gotoFullscreen() { setScreenFullscreen(); JZUtils.hideStatusBar(jzvdContext); - JZUtils.setRequestedOrientation(jzvdContext, FULLSCREEN_ORIENTATION); +// JZUtils.setRequestedOrientation(jzvdContext, FULLSCREEN_ORIENTATION); + setFullScreenOrientation(isVideoLandscape); JZUtils.hideSystemUI(jzvdContext);//华为手机和有虚拟键的手机全屏时可隐藏虚拟键 issue:1326 }