-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
public void onPositionDiscontinuity() {
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 {
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());
}

View File

@ -45,7 +45,7 @@ public abstract class PlayQueue {
streams = Collections.synchronizedList(new ArrayList<PlayQueueItem>());
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<PlayQueueMessage> getSelfReporter() {
return new Subscriber<PlayQueueMessage>() {
@Override

View File

@ -9,39 +9,46 @@
android:background="?attr/contrast_background_color"
android:paddingBottom="6dp">
<Button
android:id="@+id/playlist_play_all_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical|right"
android:layout_marginRight="2dp"
android:text="@string/play_all"
android:textSize="@dimen/channel_rss_title_size"
android:theme="@style/RedButton"
tools:ignore="RtlHardcoded"
tools:visibility="visible"/>
<TextView
android:id="@+id/playlist_title_view"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="6dp"
android:layout_toLeftOf="@+id/playlist_play_all_button"
android:layout_toStartOf="@+id/playlist_play_all_button"
android:ellipsize="end"
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceLarge"
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"/>
android:id="@+id/top_control">
<Button
android:id="@+id/playlist_play_all_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical|right"
android:layout_marginRight="2dp"
android:text="@string/play_all"
android:textSize="@dimen/channel_rss_title_size"
android:theme="@style/RedButton"
tools:ignore="RtlHardcoded"
tools:visibility="visible"/>
<TextView
android:id="@+id/playlist_title_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="6dp"
android:layout_toLeftOf="@+id/playlist_play_all_button"
android:layout_toStartOf="@+id/playlist_play_all_button"
android:layout_centerInParent="true"
android:ellipsize="end"
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceLarge"
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"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/uploader_layout"
android:layout_width="match_parent"
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_marginRight="6dp"
android:layout_marginTop="6dp"
@ -83,8 +90,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/uploader_layout"
android:layout_alignEnd="@+id/playlist_play_all_button"
android:layout_alignRight="@+id/playlist_play_all_button"
android:layout_alignEnd="@+id/top_control"
android:layout_alignRight="@+id/top_control"
android:layout_alignTop="@+id/uploader_layout"
android:layout_marginRight="6dp"
android:ellipsize="end"