Skip to content

Commit 6740af2

Browse files
authored
Fix video playback when exiting popup to main screen (#13437)
Fix for the issue ( #6400 ) wrong video plays when exiting popup mode to fullscreen.
1 parent c169232 commit 6740af2

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public final class VideoDetailFragment
205205
int lastStableBottomSheetState = BottomSheetBehavior.STATE_EXPANDED;
206206
@State
207207
protected boolean autoPlayEnabled = true;
208+
private boolean forceFullscreen = false;
208209

209210
@Nullable
210211
private StreamInfo currentInfo = null;
@@ -877,7 +878,7 @@ private void runWorker(final boolean forceLoad, final boolean addToBackStack) {
877878
}
878879
}
879880

880-
if (isAutoplayEnabled()) {
881+
if (isAutoplayEnabled() || forceFullscreen) {
881882
openVideoPlayerAutoFullscreen();
882883
}
883884
}
@@ -1134,15 +1135,29 @@ public void openVideoPlayer(final boolean directlyFullscreenIfApplicable) {
11341135
}
11351136

11361137
/**
1137-
* If the option to start directly fullscreen is enabled, calls
1138-
* {@link #openVideoPlayer(boolean)} with {@code directlyFullscreenIfApplicable = true}, so that
1139-
* if the user is not already in landscape and he has screen orientation locked the activity
1140-
* rotates and fullscreen starts. Otherwise, if the option to start directly fullscreen is
1141-
* disabled, calls {@link #openVideoPlayer(boolean)} with {@code directlyFullscreenIfApplicable
1142-
* = false}, hence preventing it from going directly fullscreen.
1138+
* If the option to start directly fullscreen is enabled, or if {@code forceFullscreen} is
1139+
* {@code true} (e.g. when switching from popup player to main player with a different video),
1140+
* calls {@link #openVideoPlayer(boolean)} with {@code directlyFullscreenIfApplicable = true},
1141+
* so that if the user is not already in landscape and he has screen orientation locked the
1142+
* activity rotates and fullscreen starts. Otherwise, if the option to start directly fullscreen
1143+
* is disabled and {@code forceFullscreen} is {@code false}, calls
1144+
* {@link #openVideoPlayer(boolean)} with {@code directlyFullscreenIfApplicable = false},
1145+
* hence preventing it from going directly fullscreen.
1146+
* {@code forceFullscreen} is reset to {@code false} after this call.
11431147
*/
11441148
public void openVideoPlayerAutoFullscreen() {
1145-
openVideoPlayer(PlayerHelper.isStartMainPlayerFullscreenEnabled(requireContext()));
1149+
openVideoPlayer(forceFullscreen
1150+
|| PlayerHelper.isStartMainPlayerFullscreenEnabled(requireContext()));
1151+
forceFullscreen = false;
1152+
}
1153+
1154+
public void setForceFullscreen(final boolean force) {
1155+
this.forceFullscreen = force;
1156+
}
1157+
1158+
@Nullable
1159+
public String getUrl() {
1160+
return url;
11461161
}
11471162

11481163
private void openNormalBackgroundPlayer(final boolean append) {

app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.schabi.newpipe.util;
22

33
import static android.text.TextUtils.isEmpty;
4+
import android.text.TextUtils;
45
import static org.schabi.newpipe.util.ListHelper.getUrlAndNonTorrentStreams;
56

67
import android.annotation.SuppressLint;
@@ -430,13 +431,16 @@ public static void openVideoDetailFragment(@NonNull final Context context,
430431
final RunnableWithVideoDetailFragment onVideoDetailFragmentReady = detailFragment -> {
431432
expandMainPlayer(detailFragment.requireActivity());
432433
detailFragment.setAutoPlay(autoPlay);
433-
if (switchingPlayers) {
434+
if (switchingPlayers && TextUtils.equals(detailFragment.getUrl(), url)) {
434435
// Situation when user switches from players to main player. All needed data is
435436
// here, we can start watching (assuming newQueue equals playQueue).
436437
// Starting directly in fullscreen if the previous player type was popup.
437438
detailFragment.openVideoPlayer(playerType == PlayerType.POPUP
438439
|| PlayerHelper.isStartMainPlayerFullscreenEnabled(context));
439440
} else {
441+
if (switchingPlayers && playerType == PlayerType.POPUP) {
442+
detailFragment.setForceFullscreen(true);
443+
}
440444
detailFragment.selectAndLoadVideo(serviceId, url, title, playQueue);
441445
}
442446
detailFragment.scrollToTop();

0 commit comments

Comments
 (0)