Skip to content

Commit

Permalink
改进屏幕旋转逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
Doikki committed Jan 22, 2019
1 parent 2bc637d commit d9c3e17
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class PIPActivity extends AppCompatActivity{
private PIPManager mPIPManager;
// private static final String URL = "rtmp://live.hkstv.hk.lxdns.com/live/hks";
private static final String URL = "http://220.161.87.62:8800/hls/0/index.m3u8";
private static final String URL = "http://mov.bn.netease.com/open-movie/nos/flv/2017/01/03/SC8U8K7BC_hd.flv";

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand All @@ -34,7 +34,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mPIPManager = PIPManager.getInstance();
IjkVideoView ijkVideoView = mPIPManager.getIjkVideoView();
StandardVideoController controller = new StandardVideoController(this);
controller.setLive();
ijkVideoView.setVideoController(controller);
if (mPIPManager.isStartFloatWindow()) {
mPIPManager.stopFloatWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ public abstract class BaseIjkVideoView extends FrameLayout implements MediaPlaye
* 加速度传感器监听
*/
protected OrientationEventListener mOrientationEventListener = new OrientationEventListener(getContext()) { // 加速度传感器监听,用于自动旋转屏幕
private long mLastTime;
@Override
public void onOrientationChanged(int orientation) {
long currentTime = System.currentTimeMillis();
if (currentTime - mLastTime < 300) return;//300毫秒检测一次
if (mVideoController == null) return;
Activity activity = PlayerUtils.scanForActivity(mVideoController.getContext());
if (activity == null) return;
Expand All @@ -92,6 +95,7 @@ public void onOrientationChanged(int orientation) {
} else if (orientation >= 70 && orientation <= 90) { //屏幕右边朝上
onOrientationReverseLandscape(activity);
}
mLastTime = currentTime;
}
};

Expand All @@ -115,7 +119,9 @@ protected void onOrientationPortrait(Activity activity) {
*/
protected void onOrientationLandscape(Activity activity) {
if (mCurrentOrientation == LANDSCAPE) return;
if (mCurrentOrientation == PORTRAIT && isFullScreen()) {
if (mCurrentOrientation == PORTRAIT
&& activity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
&& isFullScreen()) {
mCurrentOrientation = LANDSCAPE;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,9 @@ public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus) {
//重新获得焦点时保持全屏状态
mHideNavBarView.setSystemUiVisibility(FULLSCREEN_FLAGS);

}

if (mPlayerConfig.mAutoRotate || mIsFullScreen) {
if (isInPlaybackState() && (mPlayerConfig.mAutoRotate || mIsFullScreen)) {
if (hasFocus) {
postDelayed(new Runnable() {
@Override
Expand Down

0 comments on commit d9c3e17

Please sign in to comment.