Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2454,12 +2454,8 @@ private void setMediaSourcesInternal(
int currentWindowIndex = getCurrentWindowIndexInternal(playbackInfo);
long currentPositionMs = getCurrentPosition();
pendingOperationAcks++;
if (!mediaSourceHolderSnapshots.isEmpty()) {
removeMediaSourceHolders(
/* fromIndex= */ 0, /* toIndexExclusive= */ mediaSourceHolderSnapshots.size());
}
List<MediaSourceList.MediaSourceHolder> holders =
addMediaSourceHolders(/* index= */ 0, mediaSources);
setMediaSourceHolders(mediaSources, startWindowIndex);
Timeline timeline = createMaskingTimeline();
if (!timeline.isEmpty() && startWindowIndex >= timeline.getWindowCount()) {
throw new IllegalSeekPositionException(timeline, startWindowIndex, startPositionMs);
Expand Down Expand Up @@ -2505,6 +2501,21 @@ private void setMediaSourcesInternal(
/* repeatCurrentMediaItem= */ false);
}

private List<MediaSourceList.MediaSourceHolder> setMediaSourceHolders(
List<MediaSource> mediaSources, int startIndex) {
mediaSourceHolderSnapshots.clear();
List<MediaSourceList.MediaSourceHolder> holders = new ArrayList<>();
for (int i = 0; i < mediaSources.size(); i++) {
MediaSourceList.MediaSourceHolder holder =
new MediaSourceList.MediaSourceHolder(mediaSources.get(i), useLazyPreparation);
holders.add(holder);
mediaSourceHolderSnapshots.add(
i, new MediaSourceHolderSnapshot(holder.uid, holder.mediaSource));
}
shuffleOrder = shuffleOrder.cloneAndSet(/* insertionCount= */ holders.size(), startIndex);
return holders;
}

private List<MediaSourceList.MediaSourceHolder> addMediaSourceHolders(
int index, List<MediaSource> mediaSources) {
List<MediaSourceList.MediaSourceHolder> holders = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,22 @@ default ShuffleOrder cloneAndMove(int indexFrom, int indexToExclusive, int newIn
return this;
}

/**
* Returns a copy of the shuffle order with all elements replaced.
*
* <p>The default implementation uses {@link #cloneAndClear} and {@link #cloneAndInsert(int, int)}
* to replace all elements in the shuffle order. Custom implementations can override this method
* if access to the {@code startIndex} is desired.
*
* @param insertionCount The number of elements.
* @param startIndex The index playback will start from after replacement, or {@link
* C#INDEX_UNSET} if the new list is empty or the index is unknown.
* @return A copy of this {@link ShuffleOrder} with the elements replaced.
*/
default ShuffleOrder cloneAndSet(int insertionCount, int startIndex) {
return cloneAndClear().cloneAndInsert(0, insertionCount);
}

/**
* Returns a copy of the shuffle order with a range of elements removed.
*
Expand Down