Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions library/src/main/java/cn/jzvd/Jzvd.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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

}
Expand Down