-Reverted current item removal and update logic.

-Updated external play queue.
This commit is contained in:
John Zhen M 2017-09-14 20:16:09 -07:00 committed by John Zhen Mo
parent f9eb2a1ee5
commit 86c7b8522e
4 changed files with 19 additions and 18 deletions

View File

@ -267,6 +267,7 @@ public abstract class BasePlayer implements Player.EventListener,
final int serviceId = intent.getIntExtra(ExternalPlayQueue.SERVICE_ID, -1);
final int index = intent.getIntExtra(ExternalPlayQueue.INDEX, 0);
final Serializable serializable = intent.getSerializableExtra(ExternalPlayQueue.STREAMS);
final String url = intent.getStringExtra(ExternalPlayQueue.URL);
final String nextPageUrl = intent.getStringExtra(ExternalPlayQueue.NEXT_PAGE_URL);
List<InfoItem> info = new ArrayList<>();
@ -276,7 +277,7 @@ public abstract class BasePlayer implements Player.EventListener,
}
}
final PlayQueue queue = new ExternalPlayQueue(serviceId, nextPageUrl, info, index);
final PlayQueue queue = new ExternalPlayQueue(serviceId, url, nextPageUrl, info, index);
initPlayback(this, queue);
}

View File

@ -120,14 +120,11 @@ public class PlaybackManager {
break;
case REMOVE:
final RemoveEvent removeEvent = (RemoveEvent) event;
if (removeEvent.isCurrent()) tryBlock();
remove(removeEvent.index(), true);
break;
if (!removeEvent.isCurrent()) {
remove(removeEvent.index());
break;
}
case UPDATE:
final UpdateEvent updateEvent = (UpdateEvent) event;
tryBlock();
remove(updateEvent.index(), false);
break;
case SHUFFLE:
tryBlock();
resetSources();
@ -275,7 +272,7 @@ public class PlaybackManager {
}
}
private void remove(final int queueIndex, final boolean cascade) {
private void remove(final int queueIndex) {
if (queueIndex < 0) return;
final int sourceIndex = sourceToQueueIndex.indexOf(queueIndex);
@ -284,11 +281,9 @@ public class PlaybackManager {
sourceToQueueIndex.remove(sourceIndex);
sources.removeMediaSource(sourceIndex);
if (cascade) {
// Will be slow on really large arrays, fast enough for typical use case
for (int i = sourceIndex; i < sourceToQueueIndex.size(); i++) {
sourceToQueueIndex.set(i, sourceToQueueIndex.get(i) - 1);
}
// Will be slow on really large arrays, fast enough for typical use case
for (int i = sourceIndex; i < sourceToQueueIndex.size(); i++) {
sourceToQueueIndex.set(i, sourceToQueueIndex.get(i) - 1);
}
}
}

View File

@ -23,6 +23,7 @@ public final class ExternalPlayQueue extends PlayQueue {
public static final String SERVICE_ID = "service_id";
public static final String INDEX = "index";
public static final String STREAMS = "streams";
public static final String URL = "url";
public static final String NEXT_PAGE_URL = "next_page_url";
private static final int RETRY_COUNT = 2;
@ -30,17 +31,20 @@ public final class ExternalPlayQueue extends PlayQueue {
private boolean isComplete;
private int serviceId;
private String playlistUrl;
private String baseUrl;
private String nextUrl;
private transient Disposable fetchReactor;
public ExternalPlayQueue(final int serviceId,
final String url,
final String nextPageUrl,
final List<InfoItem> streams,
final int index) {
super(index, extractPlaylistItems(streams));
this.playlistUrl = nextPageUrl;
this.baseUrl = url;
this.nextUrl = nextPageUrl;
this.serviceId = serviceId;
this.isComplete = nextPageUrl == null || nextPageUrl.isEmpty();
@ -53,7 +57,7 @@ public final class ExternalPlayQueue extends PlayQueue {
@Override
public void fetch() {
ExtractorHelper.getMorePlaylistItems(this.serviceId, this.playlistUrl)
ExtractorHelper.getMorePlaylistItems(this.serviceId, this.baseUrl, this.nextUrl)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retry(RETRY_COUNT)
@ -74,7 +78,7 @@ public final class ExternalPlayQueue extends PlayQueue {
@Override
public void onSuccess(@NonNull ListExtractor.NextItemsResult result) {
if (!result.hasMoreStreams()) isComplete = true;
playlistUrl = result.nextItemsUrl;
nextUrl = result.nextItemsUrl;
append(extractPlaylistItems(result.nextItemsList));
}

View File

@ -64,6 +64,7 @@ public class NavigationHelper {
.putExtra(ExternalPlayQueue.SERVICE_ID, info.service_id)
.putExtra(ExternalPlayQueue.INDEX, index)
.putExtra(ExternalPlayQueue.STREAMS, streams)
.putExtra(ExternalPlayQueue.URL, info.url)
.putExtra(ExternalPlayQueue.NEXT_PAGE_URL, info.next_streams_url);
}