-Fix play queue remove.

-Fix player discontinuity refresh.
This commit is contained in:
John Zhen M 2017-09-04 11:05:13 -07:00 committed by John Zhen Mo
parent 73f46d3762
commit a91ef2ce9e
4 changed files with 63 additions and 36 deletions

View File

@ -550,7 +550,7 @@ public abstract class BasePlayer implements Player.EventListener,
@Override @Override
public void onPositionDiscontinuity() { public void onPositionDiscontinuity() {
int newIndex = simpleExoPlayer.getCurrentWindowIndex(); int newIndex = simpleExoPlayer.getCurrentWindowIndex();
playbackManager.refresh(newIndex); if (playbackManager.getCurrentSourceIndex() != newIndex) playbackManager.refresh(newIndex);
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////

View File

@ -19,6 +19,7 @@ import io.reactivex.schedulers.Schedulers;
public class ExternalPlayQueue extends PlayQueue { public class ExternalPlayQueue extends PlayQueue {
private final String TAG = "ExternalPlayQueue@" + Integer.toHexString(hashCode()); private final String TAG = "ExternalPlayQueue@" + Integer.toHexString(hashCode());
private static final int RETRY_COUNT = 2;
private boolean isComplete; private boolean isComplete;
@ -55,7 +56,7 @@ public class ExternalPlayQueue extends PlayQueue {
ExtractorHelper.getPlaylistInfo(this.serviceId, this.playlistUrl, false) ExtractorHelper.getPlaylistInfo(this.serviceId, this.playlistUrl, false)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.retry(2) .retry(RETRY_COUNT)
.subscribe(getPlaylistObserver()); .subscribe(getPlaylistObserver());
} }

View File

@ -45,7 +45,7 @@ public abstract class PlayQueue {
streams = Collections.synchronizedList(new ArrayList<PlayQueueItem>()); streams = Collections.synchronizedList(new ArrayList<PlayQueueItem>());
streams.addAll(startWith); streams.addAll(startWith);
queueIndex = new AtomicInteger(97); queueIndex = new AtomicInteger(index);
eventBroadcast = BehaviorSubject.create(); eventBroadcast = BehaviorSubject.create();
broadcastReceiver = eventBroadcast broadcastReceiver = eventBroadcast
@ -55,6 +55,10 @@ public abstract class PlayQueue {
if (DEBUG) broadcastReceiver.subscribe(getSelfReporter()); if (DEBUG) broadcastReceiver.subscribe(getSelfReporter());
} }
/*//////////////////////////////////////////////////////////////////////////
// Playlist actions
//////////////////////////////////////////////////////////////////////////*/
// a queue is complete if it has loaded all items in an external playlist // a queue is complete if it has loaded all items in an external playlist
// single stream or local queues are always complete // single stream or local queues are always complete
public abstract boolean isComplete(); public abstract boolean isComplete();
@ -71,6 +75,10 @@ public abstract class PlayQueue {
reportingReactor = null; reportingReactor = null;
} }
/*//////////////////////////////////////////////////////////////////////////
// Readonly ops
//////////////////////////////////////////////////////////////////////////*/
public PlayQueueItem getCurrent() { public PlayQueueItem getCurrent() {
return streams.get(getIndex()); return streams.get(getIndex());
} }
@ -89,10 +97,6 @@ public abstract class PlayQueue {
return broadcastReceiver; return broadcastReceiver;
} }
private void broadcast(final PlayQueueMessage event) {
eventBroadcast.onNext(event);
}
public int indexOf(final PlayQueueItem item) { public int indexOf(final PlayQueueItem item) {
// reference equality, can't think of a better way to do this // reference equality, can't think of a better way to do this
// todo: better than this // todo: better than this
@ -103,6 +107,10 @@ public abstract class PlayQueue {
return queueIndex.get(); return queueIndex.get();
} }
/*//////////////////////////////////////////////////////////////////////////
// Write ops
//////////////////////////////////////////////////////////////////////////*/
public void setIndex(final int index) { public void setIndex(final int index) {
queueIndex.set(Math.min(Math.max(0, index), streams.size() - 1)); queueIndex.set(Math.min(Math.max(0, index), streams.size() - 1));
broadcast(new SelectEvent(index)); broadcast(new SelectEvent(index));
@ -122,7 +130,10 @@ public abstract class PlayQueue {
if (index >= streams.size()) return; if (index >= streams.size()) return;
streams.remove(index); 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)); 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<PlayQueueMessage> getSelfReporter() { private Subscriber<PlayQueueMessage> getSelfReporter() {
return new Subscriber<PlayQueueMessage>() { return new Subscriber<PlayQueueMessage>() {
@Override @Override

View File

@ -9,6 +9,11 @@
android:background="?attr/contrast_background_color" android:background="?attr/contrast_background_color"
android:paddingBottom="6dp"> android:paddingBottom="6dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/top_control">
<Button <Button
android:id="@+id/playlist_play_all_button" android:id="@+id/playlist_play_all_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -31,17 +36,19 @@
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
android:layout_toLeftOf="@+id/playlist_play_all_button" android:layout_toLeftOf="@+id/playlist_play_all_button"
android:layout_toStartOf="@+id/playlist_play_all_button" android:layout_toStartOf="@+id/playlist_play_all_button"
android:layout_centerInParent="true"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="2" android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceLarge" android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="@dimen/playlist_detail_title_text_size" android:textSize="@dimen/playlist_detail_title_text_size"
tools:text="Mix musics #23 title Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tristique vitae sem vitae blanditLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsum"/> tools:text="Mix musics #23 title Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tristique vitae sem vitae blanditLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsum"/>
</RelativeLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/uploader_layout" android:id="@+id/uploader_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/playlist_detail_uploader_layout_height" android:layout_height="@dimen/playlist_detail_uploader_layout_height"
android:layout_below="@+id/playlist_title_view" android:layout_below="@+id/top_control"
android:layout_marginLeft="4dp" android:layout_marginLeft="4dp"
android:layout_marginRight="6dp" android:layout_marginRight="6dp"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
@ -83,8 +90,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="@+id/uploader_layout" android:layout_alignBottom="@+id/uploader_layout"
android:layout_alignEnd="@+id/playlist_play_all_button" android:layout_alignEnd="@+id/top_control"
android:layout_alignRight="@+id/playlist_play_all_button" android:layout_alignRight="@+id/top_control"
android:layout_alignTop="@+id/uploader_layout" android:layout_alignTop="@+id/uploader_layout"
android:layout_marginRight="6dp" android:layout_marginRight="6dp"
android:ellipsize="end" android:ellipsize="end"