mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-11-04 01:03:00 +00:00 
			
		
		
		
	Merge pull request #9706 from Jared234/9131_bug_background_player
Fixed a bug that caused the background player to stop working
This commit is contained in:
		@@ -865,7 +865,8 @@ public final class VideoDetailFragment
 | 
			
		||||
                            if (playQueue == null) {
 | 
			
		||||
                                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));
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
@@ -1779,7 +1780,7 @@ public final class VideoDetailFragment
 | 
			
		||||
        // deleted/added items inside Channel/Playlist queue and makes possible to have
 | 
			
		||||
        // a history of played items
 | 
			
		||||
        @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();
 | 
			
		||||
            if (playQueueItem != null) {
 | 
			
		||||
                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
 | 
			
		||||
        // then changes screen orientation. In that case the fragment will set itself as
 | 
			
		||||
        // a service listener and will receive initial call to onMetadataUpdate()
 | 
			
		||||
        if (!queue.equals(playQueue)) {
 | 
			
		||||
        if (!queue.equalStreams(playQueue)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -2102,7 +2103,7 @@ public final class VideoDetailFragment
 | 
			
		||||
        final Iterator<StackItem> iterator = stack.descendingIterator();
 | 
			
		||||
        while (iterator.hasNext()) {
 | 
			
		||||
            final StackItem next = iterator.next();
 | 
			
		||||
            if (next.getPlayQueue().equals(queue)) {
 | 
			
		||||
            if (next.getPlayQueue().equalStreams(queue)) {
 | 
			
		||||
                item = next;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
@@ -2117,7 +2118,7 @@ public final class VideoDetailFragment
 | 
			
		||||
        if (isClearingQueueConfirmationRequired(activity)
 | 
			
		||||
                && playerIsNotStopped()
 | 
			
		||||
                && activeQueue != null
 | 
			
		||||
                && !activeQueue.equals(playQueue)) {
 | 
			
		||||
                && !activeQueue.equalStreams(playQueue)) {
 | 
			
		||||
            showClearingQueueConfirmation(onAllow);
 | 
			
		||||
        } else {
 | 
			
		||||
            onAllow.run();
 | 
			
		||||
 
 | 
			
		||||
@@ -348,7 +348,7 @@ public final class Player implements PlaybackListener, Listener {
 | 
			
		||||
        final boolean playbackSkipSilence = getPrefs().getBoolean(getContext().getString(
 | 
			
		||||
                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 boolean playWhenReady = intent.getBooleanExtra(PLAY_WHEN_READY, true);
 | 
			
		||||
        final boolean isMuted = intent.getBooleanExtra(IS_MUTED, isMuted());
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
     * VideoDetailFragment without duplicating items from two identical queues
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean equals(@Nullable final Object obj) {
 | 
			
		||||
        if (!(obj instanceof PlayQueue)) {
 | 
			
		||||
    public boolean equalStreams(@Nullable final PlayQueue other) {
 | 
			
		||||
        if (other == null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        final PlayQueue other = (PlayQueue) obj;
 | 
			
		||||
        if (size() != other.size()) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
@@ -539,9 +537,11 @@ public abstract class PlayQueue implements Serializable {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int hashCode() {
 | 
			
		||||
        return streams.hashCode();
 | 
			
		||||
    public boolean equalStreamsAndIndex(@Nullable final PlayQueue other) {
 | 
			
		||||
        if (equalStreams(other)) {
 | 
			
		||||
            return other.getIndex() == getIndex();
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isDisposed() {
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,6 @@ import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertEquals;
 | 
			
		||||
import static org.junit.Assert.assertFalse;
 | 
			
		||||
import static org.junit.Assert.assertNotEquals;
 | 
			
		||||
import static org.junit.Assert.assertNull;
 | 
			
		||||
import static org.junit.Assert.assertSame;
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
@@ -169,7 +168,8 @@ public class PlayQueueTest {
 | 
			
		||||
            final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
 | 
			
		||||
            final PlayQueue queue1 = makePlayQueue(0, streams);
 | 
			
		||||
            final PlayQueue queue2 = makePlayQueue(0, streams);
 | 
			
		||||
            assertEquals(queue1, queue2);
 | 
			
		||||
            assertTrue(queue1.equalStreams(queue2));
 | 
			
		||||
            assertTrue(queue1.equalStreamsAndIndex(queue2));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Test
 | 
			
		||||
@@ -177,7 +177,8 @@ public class PlayQueueTest {
 | 
			
		||||
            final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
 | 
			
		||||
            final PlayQueue queue1 = makePlayQueue(1, streams);
 | 
			
		||||
            final PlayQueue queue2 = makePlayQueue(4, streams);
 | 
			
		||||
            assertEquals(queue1, queue2);
 | 
			
		||||
            assertTrue(queue1.equalStreams(queue2));
 | 
			
		||||
            assertFalse(queue1.equalStreamsAndIndex(queue2));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Test
 | 
			
		||||
@@ -186,7 +187,7 @@ public class PlayQueueTest {
 | 
			
		||||
            final List<PlayQueueItem> streams2 = Collections.nCopies(5, item2);
 | 
			
		||||
            final PlayQueue queue1 = makePlayQueue(0, streams1);
 | 
			
		||||
            final PlayQueue queue2 = makePlayQueue(0, streams2);
 | 
			
		||||
            assertNotEquals(queue1, queue2);
 | 
			
		||||
            assertFalse(queue1.equalStreams(queue2));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Test
 | 
			
		||||
@@ -195,7 +196,7 @@ public class PlayQueueTest {
 | 
			
		||||
            final List<PlayQueueItem> streams2 = Collections.nCopies(6, item2);
 | 
			
		||||
            final PlayQueue queue1 = makePlayQueue(0, streams1);
 | 
			
		||||
            final PlayQueue queue2 = makePlayQueue(0, streams2);
 | 
			
		||||
            assertNotEquals(queue1, queue2);
 | 
			
		||||
            assertFalse(queue1.equalStreams(queue2));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user