From d2306b0fd71e2d8fe6bf7efa90e1d3d1eadcd8e6 Mon Sep 17 00:00:00 2001 From: 0x416c6578 <14030169+0x416c6578@users.noreply.github.com> Date: Wed, 4 Aug 2021 14:33:40 +0100 Subject: [PATCH 1/5] Fixed shuffle button opacity bug Parameterised shuffle state into initPlayback for potentially passing the shuffle state into the player in the future --- .../main/java/org/schabi/newpipe/player/Player.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 22e66e793..fa63b0345 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -635,6 +635,7 @@ public final class Player implements final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode()); final boolean playWhenReady = intent.getBooleanExtra(PLAY_WHEN_READY, true); final boolean isMuted = intent.getBooleanExtra(IS_MUTED, isMuted()); + final boolean shuffleMode = false; //Set the default shuffle mode to disabled /* * There are 3 situations when playback shouldn't be started from scratch (zero timestamp): @@ -691,7 +692,7 @@ public final class Player implements state.getProgressMillis()); } initPlayback(newQueue, repeatMode, playbackSpeed, playbackPitch, - playbackSkipSilence, playWhenReady, isMuted); + playbackSkipSilence, playWhenReady, isMuted, shuffleMode); }, error -> { if (DEBUG) { @@ -699,19 +700,19 @@ public final class Player implements } // In case any error we can start playback without history initPlayback(newQueue, repeatMode, playbackSpeed, playbackPitch, - playbackSkipSilence, playWhenReady, isMuted); + playbackSkipSilence, playWhenReady, isMuted, shuffleMode); }, () -> { // Completed but not found in history initPlayback(newQueue, repeatMode, playbackSpeed, playbackPitch, - playbackSkipSilence, playWhenReady, isMuted); + playbackSkipSilence, playWhenReady, isMuted, shuffleMode); } )); } else { // Good to go... // In a case of equal PlayQueues we can re-init old one but only when it is disposed initPlayback(samePlayQueue ? playQueue : newQueue, repeatMode, playbackSpeed, - playbackPitch, playbackSkipSilence, playWhenReady, isMuted); + playbackPitch, playbackSkipSilence, playWhenReady, isMuted, shuffleMode); } if (oldPlayerType != playerType && playQueue != null) { @@ -770,10 +771,12 @@ public final class Player implements final float playbackPitch, final boolean playbackSkipSilence, final boolean playOnReady, - final boolean isMuted) { + final boolean isMuted, + final boolean shuffleEnabled) { destroyPlayer(); initPlayer(playOnReady); setRepeatMode(repeatMode); + onShuffleModeEnabledChanged(shuffleEnabled); setPlaybackParameters(playbackSpeed, playbackPitch, playbackSkipSilence); playQueue = queue; From cf81c3768354dcf0127192cf054ac65cc2503d02 Mon Sep 17 00:00:00 2001 From: 0x416c6578 <14030169+0x416c6578@users.noreply.github.com> Date: Wed, 4 Aug 2021 17:21:50 +0100 Subject: [PATCH 2/5] Removed changes to the intent handler --- .../java/org/schabi/newpipe/player/Player.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index fa63b0345..edfcb35e4 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -635,7 +635,6 @@ public final class Player implements final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode()); final boolean playWhenReady = intent.getBooleanExtra(PLAY_WHEN_READY, true); final boolean isMuted = intent.getBooleanExtra(IS_MUTED, isMuted()); - final boolean shuffleMode = false; //Set the default shuffle mode to disabled /* * There are 3 situations when playback shouldn't be started from scratch (zero timestamp): @@ -692,7 +691,7 @@ public final class Player implements state.getProgressMillis()); } initPlayback(newQueue, repeatMode, playbackSpeed, playbackPitch, - playbackSkipSilence, playWhenReady, isMuted, shuffleMode); + playbackSkipSilence, playWhenReady, isMuted); }, error -> { if (DEBUG) { @@ -700,19 +699,19 @@ public final class Player implements } // In case any error we can start playback without history initPlayback(newQueue, repeatMode, playbackSpeed, playbackPitch, - playbackSkipSilence, playWhenReady, isMuted, shuffleMode); + playbackSkipSilence, playWhenReady, isMuted); }, () -> { // Completed but not found in history initPlayback(newQueue, repeatMode, playbackSpeed, playbackPitch, - playbackSkipSilence, playWhenReady, isMuted, shuffleMode); + playbackSkipSilence, playWhenReady, isMuted); } )); } else { // Good to go... // In a case of equal PlayQueues we can re-init old one but only when it is disposed initPlayback(samePlayQueue ? playQueue : newQueue, repeatMode, playbackSpeed, - playbackPitch, playbackSkipSilence, playWhenReady, isMuted, shuffleMode); + playbackPitch, playbackSkipSilence, playWhenReady, isMuted); } if (oldPlayerType != playerType && playQueue != null) { @@ -771,12 +770,11 @@ public final class Player implements final float playbackPitch, final boolean playbackSkipSilence, final boolean playOnReady, - final boolean isMuted, - final boolean shuffleEnabled) { + final boolean isMuted) { destroyPlayer(); initPlayer(playOnReady); setRepeatMode(repeatMode); - onShuffleModeEnabledChanged(shuffleEnabled); + onShuffleModeEnabledChanged(false); setPlaybackParameters(playbackSpeed, playbackPitch, playbackSkipSilence); playQueue = queue; From d66f933c69ff5064184e2502eac1c7dce520cef1 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Sat, 23 Oct 2021 16:46:56 +0200 Subject: [PATCH 3/5] Fixing the shuffle button on the UI is enough. No need for doing the heavier method ``onShuffleModeEnabledChanged(false);`` --- app/src/main/java/org/schabi/newpipe/player/Player.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index edfcb35e4..5435b9f81 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -774,7 +774,8 @@ public final class Player implements destroyPlayer(); initPlayer(playOnReady); setRepeatMode(repeatMode); - onShuffleModeEnabledChanged(false); + // #6825 - Ensure that the shuffle-button is in the correct state on the UI + setShuffleButton(binding.shuffleButton, simpleExoPlayer.getShuffleModeEnabled()); setPlaybackParameters(playbackSpeed, playbackPitch, playbackSkipSilence); playQueue = queue; From af936bc64602126f1ed06e477bc748ef617f6370 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Sat, 23 Oct 2021 17:35:42 +0200 Subject: [PATCH 4/5] Always create a backup list when shuffling The backup-list has to be created at all cost (even when current list size <= 2). Otherwise it's not possible to enter shuffle-mode (as ``isShuffled()`` always returns false)! --- .../org/schabi/newpipe/player/playqueue/PlayQueue.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java index 014c13339..76fed8e9e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java @@ -436,14 +436,16 @@ public abstract class PlayQueue implements Serializable { * top, so shuffling a size-2 list does nothing) */ public synchronized void shuffle() { + // Create a backup if it doesn't already exist + // Note: The backup-list has to be created at all cost (even when size <= 2). + // Otherwise it's not possible to enter shuffle-mode! + if (backup == null) { + backup = new ArrayList<>(streams); + } // Can't shuffle an list that's empty or only has one element if (size() <= 2) { return; } - // Create a backup if it doesn't already exist - if (backup == null) { - backup = new ArrayList<>(streams); - } final int originalIndex = getIndex(); final PlayQueueItem currentItem = getItem(); From ecac897e7b9e80690ed661bdb3c30df4f45ab3cd Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Wed, 3 Nov 2021 17:30:30 +0100 Subject: [PATCH 5/5] Fixed typo --- .../java/org/schabi/newpipe/player/playqueue/PlayQueue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java index 76fed8e9e..f2259b120 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java @@ -442,7 +442,7 @@ public abstract class PlayQueue implements Serializable { if (backup == null) { backup = new ArrayList<>(streams); } - // Can't shuffle an list that's empty or only has one element + // Can't shuffle a list that's empty or only has one element if (size() <= 2) { return; }