From dd7d253a1b39ffe66de18bb07063e443a4a42ef5 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 25 Nov 2020 11:26:14 +0100 Subject: [PATCH] Fix orientation issues --- .../fedilab/fedilabtube/PeertubeActivity.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 2f9f836..8521627 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -521,7 +521,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd isRemote = false; peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this)); videoUuid = b.getString("video_uuid", null); - setRequestedOrientation(initialOrientation); + setRequestedOrientationCustom(initialOrientation); if (comments != null && comments.size() > 0) { int number = comments.size(); comments.clear(); @@ -1215,7 +1215,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd binding.videoContainer.setLayoutParams(param); } } - //change(); } @Override @@ -1301,6 +1300,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd private void enterVideoMode() { if (playInMinimized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && player != null) { isPlayInMinimized = true; + setRequestedOrientationCustom(initialOrientation); MediaSessionCompat mediaSession = new MediaSessionCompat(this, getPackageName()); MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession); mediaSessionConnector.setPlayer(player); @@ -1332,6 +1332,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd closeCommentThread(); return; } + + if (fullScreenMode && player != null && player.isPlaying()) { + player.setPlayWhenReady(false); + return; + } + if (playInMinimized && player != null) { enterVideoMode(); } else { @@ -1359,9 +1365,13 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd binding.bottomVideo.setVisibility(View.GONE); Objects.requireNonNull(getSupportActionBar()).hide(); if (videoOrientationType == videoOrientation.LANDSCAPE) { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + if (getResources().getConfiguration().orientation != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { + setRequestedOrientationCustom(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } } else { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + if (getResources().getConfiguration().orientation != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { + setRequestedOrientationCustom(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } } } else { getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, @@ -1850,10 +1860,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd openFullscreenDialog(); } else { closeFullscreenDialog(); - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); - Handler handler = new Handler(); - handler.postDelayed(() -> setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR), 2000); - + setRequestedOrientationCustom(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } }); @@ -1877,6 +1884,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd }); } + private void setRequestedOrientationCustom(int orientationCustom) { + setRequestedOrientation(orientationCustom); + Handler handler = new Handler(); + handler.postDelayed(() -> setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR), 2000); + } + private void initResolution() { PlayerControlView controlView = binding.doubleTapPlayerView.findViewById(R.id.exo_controller); TextView resolution = controlView.findViewById(R.id.resolution);