Merge pull request #9706 from Jared234/9131_bug_background_player

Fixed a bug that caused the background player to stop working
pull/9725/head
Stypox 2023-01-28 21:56:00 +01:00 zatwierdzone przez GitHub
commit 1e724eba6c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 20 dodań i 18 usunięć

Wyświetl plik

@ -865,7 +865,8 @@ public final class VideoDetailFragment
if (playQueue == null) { if (playQueue == null) {
playQueue = new SinglePlayQueue(result); playQueue = new SinglePlayQueue(result);
} }
if (stack.isEmpty() || !stack.peek().getPlayQueue().equals(playQueue)) { if (stack.isEmpty() || !stack.peek().getPlayQueue()
.equalStreams(playQueue)) {
stack.push(new StackItem(serviceId, url, title, playQueue)); stack.push(new StackItem(serviceId, url, title, playQueue));
} }
} }
@ -1779,7 +1780,7 @@ public final class VideoDetailFragment
// deleted/added items inside Channel/Playlist queue and makes possible to have // deleted/added items inside Channel/Playlist queue and makes possible to have
// a history of played items // a history of played items
@Nullable final StackItem stackPeek = stack.peek(); @Nullable final StackItem stackPeek = stack.peek();
if (stackPeek != null && !stackPeek.getPlayQueue().equals(queue)) { if (stackPeek != null && !stackPeek.getPlayQueue().equalStreams(queue)) {
@Nullable final PlayQueueItem playQueueItem = queue.getItem(); @Nullable final PlayQueueItem playQueueItem = queue.getItem();
if (playQueueItem != null) { if (playQueueItem != null) {
stack.push(new StackItem(playQueueItem.getServiceId(), playQueueItem.getUrl(), stack.push(new StackItem(playQueueItem.getServiceId(), playQueueItem.getUrl(),
@ -1845,7 +1846,7 @@ public final class VideoDetailFragment
// They are not equal when user watches something in popup while browsing in fragment and // They are not equal when user watches something in popup while browsing in fragment and
// then changes screen orientation. In that case the fragment will set itself as // then changes screen orientation. In that case the fragment will set itself as
// a service listener and will receive initial call to onMetadataUpdate() // a service listener and will receive initial call to onMetadataUpdate()
if (!queue.equals(playQueue)) { if (!queue.equalStreams(playQueue)) {
return; return;
} }
@ -2102,7 +2103,7 @@ public final class VideoDetailFragment
final Iterator<StackItem> iterator = stack.descendingIterator(); final Iterator<StackItem> iterator = stack.descendingIterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final StackItem next = iterator.next(); final StackItem next = iterator.next();
if (next.getPlayQueue().equals(queue)) { if (next.getPlayQueue().equalStreams(queue)) {
item = next; item = next;
break; break;
} }
@ -2117,7 +2118,7 @@ public final class VideoDetailFragment
if (isClearingQueueConfirmationRequired(activity) if (isClearingQueueConfirmationRequired(activity)
&& playerIsNotStopped() && playerIsNotStopped()
&& activeQueue != null && activeQueue != null
&& !activeQueue.equals(playQueue)) { && !activeQueue.equalStreams(playQueue)) {
showClearingQueueConfirmation(onAllow); showClearingQueueConfirmation(onAllow);
} else { } else {
onAllow.run(); onAllow.run();

Wyświetl plik

@ -348,7 +348,7 @@ public final class Player implements PlaybackListener, Listener {
final boolean playbackSkipSilence = getPrefs().getBoolean(getContext().getString( final boolean playbackSkipSilence = getPrefs().getBoolean(getContext().getString(
R.string.playback_skip_silence_key), getPlaybackSkipSilence()); R.string.playback_skip_silence_key), getPlaybackSkipSilence());
final boolean samePlayQueue = playQueue != null && playQueue.equals(newQueue); final boolean samePlayQueue = playQueue != null && playQueue.equalStreamsAndIndex(newQueue);
final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode()); final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode());
final boolean playWhenReady = intent.getBooleanExtra(PLAY_WHEN_READY, true); final boolean playWhenReady = intent.getBooleanExtra(PLAY_WHEN_READY, true);
final boolean isMuted = intent.getBooleanExtra(IS_MUTED, isMuted()); final boolean isMuted = intent.getBooleanExtra(IS_MUTED, isMuted());

Wyświetl plik

@ -518,12 +518,10 @@ public abstract class PlayQueue implements Serializable {
* This method also gives a chance to track history of items in a queue in * This method also gives a chance to track history of items in a queue in
* VideoDetailFragment without duplicating items from two identical queues * VideoDetailFragment without duplicating items from two identical queues
*/ */
@Override public boolean equalStreams(@Nullable final PlayQueue other) {
public boolean equals(@Nullable final Object obj) { if (other == null) {
if (!(obj instanceof PlayQueue)) {
return false; return false;
} }
final PlayQueue other = (PlayQueue) obj;
if (size() != other.size()) { if (size() != other.size()) {
return false; return false;
} }
@ -539,9 +537,11 @@ public abstract class PlayQueue implements Serializable {
return true; return true;
} }
@Override public boolean equalStreamsAndIndex(@Nullable final PlayQueue other) {
public int hashCode() { if (equalStreams(other)) {
return streams.hashCode(); return other.getIndex() == getIndex();
}
return false;
} }
public boolean isDisposed() { public boolean isDisposed() {

Wyświetl plik

@ -13,7 +13,6 @@ import java.util.Objects;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -169,7 +168,8 @@ public class PlayQueueTest {
final List<PlayQueueItem> streams = Collections.nCopies(5, item1); final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
final PlayQueue queue1 = makePlayQueue(0, streams); final PlayQueue queue1 = makePlayQueue(0, streams);
final PlayQueue queue2 = makePlayQueue(0, streams); final PlayQueue queue2 = makePlayQueue(0, streams);
assertEquals(queue1, queue2); assertTrue(queue1.equalStreams(queue2));
assertTrue(queue1.equalStreamsAndIndex(queue2));
} }
@Test @Test
@ -177,7 +177,8 @@ public class PlayQueueTest {
final List<PlayQueueItem> streams = Collections.nCopies(5, item1); final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
final PlayQueue queue1 = makePlayQueue(1, streams); final PlayQueue queue1 = makePlayQueue(1, streams);
final PlayQueue queue2 = makePlayQueue(4, streams); final PlayQueue queue2 = makePlayQueue(4, streams);
assertEquals(queue1, queue2); assertTrue(queue1.equalStreams(queue2));
assertFalse(queue1.equalStreamsAndIndex(queue2));
} }
@Test @Test
@ -186,7 +187,7 @@ public class PlayQueueTest {
final List<PlayQueueItem> streams2 = Collections.nCopies(5, item2); final List<PlayQueueItem> streams2 = Collections.nCopies(5, item2);
final PlayQueue queue1 = makePlayQueue(0, streams1); final PlayQueue queue1 = makePlayQueue(0, streams1);
final PlayQueue queue2 = makePlayQueue(0, streams2); final PlayQueue queue2 = makePlayQueue(0, streams2);
assertNotEquals(queue1, queue2); assertFalse(queue1.equalStreams(queue2));
} }
@Test @Test
@ -195,7 +196,7 @@ public class PlayQueueTest {
final List<PlayQueueItem> streams2 = Collections.nCopies(6, item2); final List<PlayQueueItem> streams2 = Collections.nCopies(6, item2);
final PlayQueue queue1 = makePlayQueue(0, streams1); final PlayQueue queue1 = makePlayQueue(0, streams1);
final PlayQueue queue2 = makePlayQueue(0, streams2); final PlayQueue queue2 = makePlayQueue(0, streams2);
assertNotEquals(queue1, queue2); assertFalse(queue1.equalStreams(queue2));
} }
} }
} }