@@ -2513,12 +2513,8 @@ private void setMediaSourcesInternal(
25132513 int currentWindowIndex = getCurrentWindowIndexInternal (playbackInfo );
25142514 long currentPositionMs = getCurrentPosition ();
25152515 pendingOperationAcks ++;
2516- if (!mediaSourceHolderSnapshots .isEmpty ()) {
2517- removeMediaSourceHolders (
2518- /* fromIndex= */ 0 , /* toIndexExclusive= */ mediaSourceHolderSnapshots .size ());
2519- }
25202516 List <MediaSourceList .MediaSourceHolder > holders =
2521- addMediaSourceHolders ( /* index= */ 0 , mediaSources );
2517+ setMediaSourceHolders ( mediaSources , startWindowIndex );
25222518 Timeline timeline = createMaskingTimeline ();
25232519 if (!timeline .isEmpty () && startWindowIndex >= timeline .getWindowCount ()) {
25242520 throw new IllegalSeekPositionException (timeline , startWindowIndex , startPositionMs );
@@ -2564,6 +2560,21 @@ private void setMediaSourcesInternal(
25642560 /* repeatCurrentMediaItem= */ false );
25652561 }
25662562
2563+ private List <MediaSourceList .MediaSourceHolder > setMediaSourceHolders (
2564+ List <MediaSource > mediaSources , int startIndex ) {
2565+ mediaSourceHolderSnapshots .clear ();
2566+ List <MediaSourceList .MediaSourceHolder > holders = new ArrayList <>();
2567+ for (int i = 0 ; i < mediaSources .size (); i ++) {
2568+ MediaSourceList .MediaSourceHolder holder =
2569+ new MediaSourceList .MediaSourceHolder (mediaSources .get (i ), useLazyPreparation );
2570+ holders .add (holder );
2571+ mediaSourceHolderSnapshots .add (
2572+ i , new MediaSourceHolderSnapshot (holder .uid , holder .mediaSource ));
2573+ }
2574+ shuffleOrder = shuffleOrder .cloneAndSet (/* insertionCount= */ holders .size (), startIndex );
2575+ return holders ;
2576+ }
2577+
25672578 private List <MediaSourceList .MediaSourceHolder > addMediaSourceHolders (
25682579 int index , List <MediaSource > mediaSources ) {
25692580 List <MediaSourceList .MediaSourceHolder > holders = new ArrayList <>();
0 commit comments