ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHolder> { @Override public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) { Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid); MediaPeriodId childMediaPeriodId = id.copyWithPeriodUid(getChildPeriodUid(id.periodUid)); MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid); if (holder == null) { holder = new MediaSourceHolder(new DummyMediaSource(), useLazyPreparation); holder.isRemoved = true; prepareChildSource(holder, holder.mediaSource); } enableMediaSource(holder); holder.activeMediaPeriodIds.add(childMediaPeriodId); MediaPeriod mediaPeriod = holder.mediaSource.createPeriod(childMediaPeriodId, allocator, startPositionUs); mediaSourceByMediaPeriod.put(mediaPeriod, holder); disableUnusedMediaSources(); return mediaPeriod; } ConcatenatingMediaSource(MediaSource... mediaSources);  ConcatenatingMediaSource(boolean isAtomic, MediaSource... mediaSources);  ConcatenatingMediaSource(
      boolean isAtomic, ShuffleOrder shuffleOrder, MediaSource... mediaSources); @SuppressWarnings("initialization")  ConcatenatingMediaSource(
      boolean isAtomic,
      boolean useLazyPreparation,
      ShuffleOrder shuffleOrder,
      MediaSource... mediaSources); synchronized void addMediaSource(MediaSource mediaSource); synchronized void addMediaSource(
      MediaSource mediaSource, Handler handler, Runnable onCompletionAction); synchronized void addMediaSource(int index, MediaSource mediaSource); synchronized void addMediaSource(
      int index, MediaSource mediaSource, Handler handler, Runnable onCompletionAction); synchronized void addMediaSources(Collection<MediaSource> mediaSources); synchronized void addMediaSources(
      Collection<MediaSource> mediaSources, Handler handler, Runnable onCompletionAction); synchronized void addMediaSources(int index, Collection<MediaSource> mediaSources); synchronized void addMediaSources(
      int index,
      Collection<MediaSource> mediaSources,
      Handler handler,
      Runnable onCompletionAction); synchronized MediaSource removeMediaSource(int index); synchronized MediaSource removeMediaSource(
      int index, Handler handler, Runnable onCompletionAction); synchronized void removeMediaSourceRange(int fromIndex, int toIndex); synchronized void removeMediaSourceRange(
      int fromIndex, int toIndex, Handler handler, Runnable onCompletionAction); synchronized void moveMediaSource(int currentIndex, int newIndex); synchronized void moveMediaSource(
      int currentIndex, int newIndex, Handler handler, Runnable onCompletionAction); synchronized void clear(); synchronized void clear(Handler handler, Runnable onCompletionAction); synchronized int getSize(); synchronized MediaSource getMediaSource(int index); synchronized void setShuffleOrder(ShuffleOrder shuffleOrder); synchronized void setShuffleOrder(
      ShuffleOrder shuffleOrder, Handler handler, Runnable onCompletionAction); @Override @Nullable Object getTag(); @Override MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs); @Override void releasePeriod(MediaPeriod mediaPeriod);  }
@Test public void testChildSourceIsPreparedWithLazyPreparationAfterPeriodCreation() throws IOException { FakeMediaSource[] childSources = createMediaSources( 2); mediaSource = new ConcatenatingMediaSource( false, true, new DefaultShuffleOrder(0), childSources); testRunner = new MediaSourceTestRunner(mediaSource, null); Timeline timeline = testRunner.prepareSource(); testRunner.createPeriod( new MediaPeriodId( timeline.getUidOfPeriod( 0), 0)); assertThat(childSources[0].isPrepared()).isTrue(); assertThat(childSources[1].isPrepared()).isFalse(); }
@Test public void testChildSourceWithLazyPreparationOnlyPreparesSourceOnce() throws IOException { FakeMediaSource[] childSources = createMediaSources( 2); mediaSource = new ConcatenatingMediaSource( false, true, new DefaultShuffleOrder(0), childSources); testRunner = new MediaSourceTestRunner(mediaSource, null); Timeline timeline = testRunner.prepareSource(); MediaPeriodId mediaPeriodId = new MediaPeriodId( timeline.getUidOfPeriod( 0), 0); testRunner.createPeriod(mediaPeriodId); testRunner.createPeriod(mediaPeriodId); }