Merge pull request #6712 from Stypox/fix-duplicate-items-queue
Fix duplicate items in queue causing endless buffering
This commit is contained in:
commit
1f9ad12593
4 changed files with 38 additions and 15 deletions
|
@ -813,7 +813,7 @@ public final class VideoDetailFragment
|
||||||
@NonNull final String newTitle,
|
@NonNull final String newTitle,
|
||||||
@Nullable final PlayQueue newQueue) {
|
@Nullable final PlayQueue newQueue) {
|
||||||
if (isPlayerAvailable() && newQueue != null && playQueue != null
|
if (isPlayerAvailable() && newQueue != null && playQueue != null
|
||||||
&& !Objects.equals(newQueue.getItem(), playQueue.getItem())) {
|
&& playQueue.getItem() != null && !playQueue.getItem().getUrl().equals(newUrl)) {
|
||||||
// Preloading can be disabled since playback is surely being replaced.
|
// Preloading can be disabled since playback is surely being replaced.
|
||||||
player.disablePreloadingOfCurrentTrack();
|
player.disablePreloadingOfCurrentTrack();
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,20 +64,6 @@ public class PlayQueueItem implements Serializable {
|
||||||
this.recoveryPosition = RECOVERY_UNSET;
|
this.recoveryPosition = RECOVERY_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(final Object o) {
|
|
||||||
if (o instanceof PlayQueueItem) {
|
|
||||||
return url.equals(((PlayQueueItem) o).url);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return url.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package org.schabi.newpipe.player.playqueue;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
public class PlayQueueItemTest {
|
||||||
|
|
||||||
|
public static final String URL = "MY_URL";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalsMustNotBeOverloaded() {
|
||||||
|
final PlayQueueItem a = PlayQueueTest.makeItemWithUrl(URL);
|
||||||
|
final PlayQueueItem b = PlayQueueTest.makeItemWithUrl(URL);
|
||||||
|
assertEquals(a, a);
|
||||||
|
assertNotEquals(a, b); // they should compare different even if they have the same data
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ 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.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
@ -148,6 +149,15 @@ public class PlayQueueTest {
|
||||||
assertNull(queue.getItem(-1));
|
assertNull(queue.getItem(-1));
|
||||||
assertNull(queue.getItem(5));
|
assertNull(queue.getItem(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void itemsAreNotCloned() {
|
||||||
|
final PlayQueueItem item = makeItemWithUrl("A url");
|
||||||
|
final PlayQueue playQueue = makePlayQueue(0, Collections.singletonList(item));
|
||||||
|
|
||||||
|
// make sure that items are not cloned when added to the queue
|
||||||
|
assertSame(playQueue.getItem(), item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EqualsTests {
|
public static class EqualsTests {
|
||||||
|
@ -162,6 +172,14 @@ public class PlayQueueTest {
|
||||||
assertEquals(queue1, queue2);
|
assertEquals(queue1, queue2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sameStreamsDifferentIndex() {
|
||||||
|
final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
|
||||||
|
final PlayQueue queue1 = makePlayQueue(1, streams);
|
||||||
|
final PlayQueue queue2 = makePlayQueue(4, streams);
|
||||||
|
assertEquals(queue1, queue2);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sameSizeDifferentItems() {
|
public void sameSizeDifferentItems() {
|
||||||
final List<PlayQueueItem> streams1 = Collections.nCopies(5, item1);
|
final List<PlayQueueItem> streams1 = Collections.nCopies(5, item1);
|
||||||
|
|
Loading…
Reference in a new issue