From a91ef2ce9ef9ac6790ba77a87b16db72302ba310 Mon Sep 17 00:00:00 2001 From: John Zhen M Date: Mon, 4 Sep 2017 11:05:13 -0700 Subject: [PATCH] -Fix play queue remove. -Fix player discontinuity refresh. --- .../org/schabi/newpipe/player/BasePlayer.java | 2 +- .../newpipe/playlist/ExternalPlayQueue.java | 3 +- .../schabi/newpipe/playlist/PlayQueue.java | 31 +++++++-- app/src/main/res/layout/playlist_header.xml | 63 ++++++++++--------- 4 files changed, 63 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index c845bd825..2ea0d9860 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -550,7 +550,7 @@ public abstract class BasePlayer implements Player.EventListener, @Override public void onPositionDiscontinuity() { int newIndex = simpleExoPlayer.getCurrentWindowIndex(); - playbackManager.refresh(newIndex); + if (playbackManager.getCurrentSourceIndex() != newIndex) playbackManager.refresh(newIndex); } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/playlist/ExternalPlayQueue.java b/app/src/main/java/org/schabi/newpipe/playlist/ExternalPlayQueue.java index 63bfe7ab1..f2927e922 100644 --- a/app/src/main/java/org/schabi/newpipe/playlist/ExternalPlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/playlist/ExternalPlayQueue.java @@ -19,6 +19,7 @@ import io.reactivex.schedulers.Schedulers; public class ExternalPlayQueue extends PlayQueue { private final String TAG = "ExternalPlayQueue@" + Integer.toHexString(hashCode()); + private static final int RETRY_COUNT = 2; private boolean isComplete; @@ -55,7 +56,7 @@ public class ExternalPlayQueue extends PlayQueue { ExtractorHelper.getPlaylistInfo(this.serviceId, this.playlistUrl, false) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .retry(2) + .retry(RETRY_COUNT) .subscribe(getPlaylistObserver()); } diff --git a/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java b/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java index a1c759150..c32417ee2 100644 --- a/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java @@ -45,7 +45,7 @@ public abstract class PlayQueue { streams = Collections.synchronizedList(new ArrayList()); streams.addAll(startWith); - queueIndex = new AtomicInteger(97); + queueIndex = new AtomicInteger(index); eventBroadcast = BehaviorSubject.create(); broadcastReceiver = eventBroadcast @@ -55,6 +55,10 @@ public abstract class PlayQueue { if (DEBUG) broadcastReceiver.subscribe(getSelfReporter()); } + /*////////////////////////////////////////////////////////////////////////// + // Playlist actions + //////////////////////////////////////////////////////////////////////////*/ + // a queue is complete if it has loaded all items in an external playlist // single stream or local queues are always complete public abstract boolean isComplete(); @@ -71,6 +75,10 @@ public abstract class PlayQueue { reportingReactor = null; } + /*////////////////////////////////////////////////////////////////////////// + // Readonly ops + //////////////////////////////////////////////////////////////////////////*/ + public PlayQueueItem getCurrent() { return streams.get(getIndex()); } @@ -89,10 +97,6 @@ public abstract class PlayQueue { return broadcastReceiver; } - private void broadcast(final PlayQueueMessage event) { - eventBroadcast.onNext(event); - } - public int indexOf(final PlayQueueItem item) { // reference equality, can't think of a better way to do this // todo: better than this @@ -103,6 +107,10 @@ public abstract class PlayQueue { return queueIndex.get(); } + /*////////////////////////////////////////////////////////////////////////// + // Write ops + //////////////////////////////////////////////////////////////////////////*/ + public void setIndex(final int index) { queueIndex.set(Math.min(Math.max(0, index), streams.size() - 1)); broadcast(new SelectEvent(index)); @@ -122,7 +130,10 @@ public abstract class PlayQueue { if (index >= streams.size()) return; streams.remove(index); - queueIndex.set(Math.max(0, queueIndex.get() - 1)); + // Nudge the index if it becomes larger than the queue size + if (queueIndex.get() > size()) { + queueIndex.set(size() - 1); + } broadcast(new RemoveEvent(index)); } @@ -148,6 +159,14 @@ public abstract class PlayQueue { } } + /*////////////////////////////////////////////////////////////////////////// + // Rx Broadcast + //////////////////////////////////////////////////////////////////////////*/ + + private void broadcast(final PlayQueueMessage event) { + eventBroadcast.onNext(event); + } + private Subscriber getSelfReporter() { return new Subscriber() { @Override diff --git a/app/src/main/res/layout/playlist_header.xml b/app/src/main/res/layout/playlist_header.xml index 5c054fcca..9e136ba0f 100644 --- a/app/src/main/res/layout/playlist_header.xml +++ b/app/src/main/res/layout/playlist_header.xml @@ -9,39 +9,46 @@ android:background="?attr/contrast_background_color" android:paddingBottom="6dp"> -