提交 bfc96417 编写于 作者: S shuyu

add AutoFullWithSize support

上级 0cf9e057
......@@ -79,8 +79,9 @@ public class ListNormalAdapter extends BaseAdapter {
//final String url = "https://res.exexm.com/cw_145225549855002";
final String url = "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4";
//final String url = "http://7xse1z.com1.z0.glb.clouddn.com/1491813192";
final String urlH = "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4";
final String urlV = "http://7xse1z.com1.z0.glb.clouddn.com/1491813192";
final String url = (position % 2 == 0) ? urlH : urlV;
//final String url = "http://111.198.24.133:83/yyy_login_server/pic/YB059284/97778276040859/1.mp4";
......@@ -95,7 +96,7 @@ public class ListNormalAdapter extends BaseAdapter {
//默认缓存路径
//使用lazy的set可以避免滑动卡的情况存在
holder.gsyVideoPlayer.setUpLazy(url, true, null, null, "这是title");
holder.gsyVideoPlayer.setUpLazy(url, false, null, null, "这是title");
//holder.gsyVideoPlayer.setNeedShowWifiTip(false);
......@@ -247,7 +248,7 @@ public class ListNormalAdapter extends BaseAdapter {
* @return 返回true为支持列表重力全屏
*/
public boolean getListNeedAutoLand() {
return true;
return false;
}
private void initOrientationUtils(StandardGSYVideoPlayer standardGSYVideoPlayer, boolean full) {
......
......@@ -21,9 +21,12 @@ public class OrientationUtils {
private int screenType = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
private int mIsLand;
private boolean mClick, mClickLand, mClickPort;
private boolean mClick = false;
private boolean mClickLand = false;
private boolean mClickPort;
private boolean mEnable = true;
private boolean mRotateWithSystem = true; //是否跟随系统
//是否跟随系统
private boolean mRotateWithSystem = true;
/**
* @param activity
......@@ -42,7 +45,7 @@ public class OrientationUtils {
boolean autoRotateOn = (Settings.System.getInt(activity.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1);
if (!autoRotateOn && mRotateWithSystem) {
//if (mIsLand == 0) {
return;
return;
//}
}
// 设置竖屏
......@@ -231,6 +234,7 @@ public class OrientationUtils {
/**
* 是否更新系统旋转,false的话,系统禁止旋转也会跟着旋转
*
* @param rotateWithSystem 默认true
*/
public void setRotateWithSystem(boolean rotateWithSystem) {
......
......@@ -22,6 +22,8 @@ import com.transitionseverywhere.TransitionManager;
import java.lang.reflect.Constructor;
import tv.danmaku.ijk.media.player.IMediaPlayer;
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.getActionBarHeight;
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.getStatusBarHeight;
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.hideNavKey;
......@@ -63,6 +65,9 @@ public abstract class GSYBaseVideoPlayer extends GSYVideoControlView {
//当前全屏是否锁定全屏
protected boolean mLockLand = false;
//是否根据视频尺寸,自动选择竖屏全屏或者横屏全屏,注意,这时候默认旋转无效
protected boolean mAutoFullWithSize = false;
//小窗口关闭按键
protected View mSmallClose;
......@@ -139,13 +144,28 @@ public abstract class GSYBaseVideoPlayer extends GSYVideoControlView {
super.lockTouchLogic();
if (mLockCurScreen) {
if (mOrientationUtils != null)
mOrientationUtils.setEnable(mRotateViewAuto);
mOrientationUtils.setEnable(isRotateViewAuto());
} else {
if (mOrientationUtils != null)
mOrientationUtils.setEnable(false);
}
}
@Override
public void onPrepared() {
super.onPrepared();
//确保开启竖屏检测的时候正常全屏
checkAutoFullSizeWhenFull();
}
@Override
public void onInfo(int what, int extra) {
super.onInfo(what, extra);
if (what == IMediaPlayer.MEDIA_INFO_VIDEO_ROTATION_CHANGED) {
checkAutoFullSizeWhenFull();
}
}
private ViewGroup getViewGroup() {
return (ViewGroup) (CommonUtil.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT);
......@@ -216,6 +236,7 @@ public abstract class GSYBaseVideoPlayer extends GSYVideoControlView {
to.mVideoAllCallBack = from.mVideoAllCallBack;
to.mActionBar = from.mActionBar;
to.mStatusBar = from.mStatusBar;
to.mAutoFullWithSize = from.mAutoFullWithSize;
if (from.mSetUpLazy) {
to.setUpLazy(from.mOriginUrl, from.mCache, from.mCachePath, from.mMapHeadData, from.mTitle);
to.mUrl = from.mUrl;
......@@ -278,15 +299,20 @@ public abstract class GSYBaseVideoPlayer extends GSYVideoControlView {
gsyVideoPlayer.setLayoutParams(lp);
gsyVideoPlayer.setIfCurrentIsFullscreen(true);
mOrientationUtils = new OrientationUtils((Activity) context, gsyVideoPlayer);
mOrientationUtils.setEnable(mRotateViewAuto);
mOrientationUtils.setEnable(isRotateViewAuto());
mOrientationUtils.setRotateWithSystem(mRotateWithSystem);
gsyVideoPlayer.mOrientationUtils = mOrientationUtils;
final boolean isVertical = isVerticalVideoFull();
final boolean isLockLand = isLockLandByAutoFullSize();
if (isShowFullAnimation()) {
postDelayed(new Runnable() {
@Override
public void run() {
if (mLockLand && mOrientationUtils.getIsLand() != 1) {
Debuger.printfLog("GSYVideoBase resolveFullVideoShow isVerticalVideoFull " + isVertical);
//autoFull模式下,非横屏视频视频不横屏,并且不自动旋转
if (!isVertical && isLockLand && mOrientationUtils.getIsLand() != 1) {
mOrientationUtils.resolveByClick();
}
gsyVideoPlayer.setVisibility(VISIBLE);
......@@ -294,7 +320,7 @@ public abstract class GSYBaseVideoPlayer extends GSYVideoControlView {
}
}, 300);
} else {
if (mLockLand) {
if (!isVertical && isLockLand) {
mOrientationUtils.resolveByClick();
}
gsyVideoPlayer.setVisibility(VISIBLE);
......@@ -441,6 +467,58 @@ public abstract class GSYBaseVideoPlayer extends GSYVideoControlView {
postDelayed(mCheckoutTask, 500);
}
/**
* 是否需要使用竖屏全屏
*/
protected boolean isVerticalVideoFull() {
return isVerticalVideo() && isAutoFullWithSize();
}
/**
* 是否竖屏模式的竖屏
*/
protected boolean isVerticalVideo() {
boolean isVertical = false;
int videoHeight = getCurrentVideoHeight();
int videoWidth = getCurrentVideoWidth();
Debuger.printfLog("GSYVideoBase isVerticalVideo videoHeight " + videoHeight + " videoWidth " + videoWidth);
Debuger.printfLog("GSYVideoBase isVerticalVideo mRotate " + mRotate);
if (videoHeight > 0 && videoWidth > 0) {
if (mRotate == 90 || mRotate == 270) {
isVertical = videoWidth > videoHeight;
} else {
isVertical = videoHeight > videoWidth;
}
}
return isVertical;
}
/**
* 是否根据autoFullSize调整lockLand
*/
protected boolean isLockLandByAutoFullSize() {
boolean isLockLand = mLockLand;
if (isAutoFullWithSize()) {
isLockLand = true;
}
return isLockLand;
}
/**
* 确保开启竖屏检测的时候正常全屏
*/
protected void checkAutoFullSizeWhenFull() {
if (mIfCurrentIsFullscreen) {
//确保开启竖屏检测的时候正常全屏
boolean isV = isVerticalVideoFull();
Debuger.printfLog("GSYVideoBase onPrepared isVerticalVideoFull " + isV);
if (isV) {
if (mOrientationUtils != null)
mOrientationUtils.backToProtVideo();
}
}
}
protected abstract int getFullId();
protected abstract int getSmallId();
......@@ -722,6 +800,9 @@ public abstract class GSYBaseVideoPlayer extends GSYVideoControlView {
}
public boolean isRotateViewAuto() {
if (mAutoFullWithSize) {
return false;
}
return mRotateViewAuto;
}
......@@ -836,4 +917,16 @@ public abstract class GSYBaseVideoPlayer extends GSYVideoControlView {
public void setSaveBeforeFullSystemUiVisibility(int systemUiVisibility) {
this.mSystemUiVisibility = systemUiVisibility;
}
public boolean isAutoFullWithSize() {
return mAutoFullWithSize;
}
/**
* 是否根据视频尺寸,自动选择竖屏全屏或者横屏全屏,注意,这时候默认旋转无效
* @param autoFullWithSize 默认false
*/
public void setAutoFullWithSize(boolean autoFullWithSize) {
this.mAutoFullWithSize = autoFullWithSize;
}
}
......@@ -1133,4 +1133,18 @@ public abstract class GSYVideoView extends GSYTextureRenderView implements GSYMe
public void setReleaseWhenLossAudio(boolean releaseWhenLossAudio) {
this.mReleaseWhenLossAudio = releaseWhenLossAudio;
}
public Map<String, String> getMapHeadData() {
return mMapHeadData;
}
/**
* 单独设置mapHeader
* @param headData
*/
public void setMapHeadData(Map<String, String> headData) {
if (headData != null) {
this.mMapHeadData = headData;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册