@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); }
@Override public final MediaPeriod createPeriod( MediaPeriodId id, Allocator allocator, long startPositionUs) { Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid); MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid); if (holder == null) { holder = new MediaSourceHolder(new DummyMediaSource()); holder.hasStartedPreparing = true; } DeferredMediaPeriod mediaPeriod = new DeferredMediaPeriod(holder.mediaSource, id, allocator, startPositionUs); mediaSourceByMediaPeriod.put(mediaPeriod, holder); holder.activeMediaPeriods.add(mediaPeriod); if (!holder.hasStartedPreparing) { holder.hasStartedPreparing = true; prepareChildSource(holder, holder.mediaSource); } else if (holder.isPrepared) { MediaPeriodId idInSource = id.copyWithPeriodUid(getChildPeriodUid(holder, id.periodUid)); mediaPeriod.createPeriod(idInSource); } return mediaPeriod; }
ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHolder> { @Override public final MediaPeriod createPeriod( MediaPeriodId id, Allocator allocator, long startPositionUs) { Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid); MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid); if (holder == null) { holder = new MediaSourceHolder(new DummyMediaSource()); holder.hasStartedPreparing = true; } DeferredMediaPeriod mediaPeriod = new DeferredMediaPeriod(holder.mediaSource, id, allocator, startPositionUs); mediaSourceByMediaPeriod.put(mediaPeriod, holder); holder.activeMediaPeriods.add(mediaPeriod); if (!holder.hasStartedPreparing) { holder.hasStartedPreparing = true; prepareChildSource(holder, holder.mediaSource); } else if (holder.isPrepared) { MediaPeriodId idInSource = id.copyWithPeriodUid(getChildPeriodUid(holder, id.periodUid)); mediaPeriod.createPeriod(idInSource); } return mediaPeriod; } }
ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHolder> { @Override public final MediaPeriod createPeriod( MediaPeriodId id, Allocator allocator, long startPositionUs) { Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid); MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid); if (holder == null) { holder = new MediaSourceHolder(new DummyMediaSource()); holder.hasStartedPreparing = true; } DeferredMediaPeriod mediaPeriod = new DeferredMediaPeriod(holder.mediaSource, id, allocator, startPositionUs); mediaSourceByMediaPeriod.put(mediaPeriod, holder); holder.activeMediaPeriods.add(mediaPeriod); if (!holder.hasStartedPreparing) { holder.hasStartedPreparing = true; prepareChildSource(holder, holder.mediaSource); } else if (holder.isPrepared) { MediaPeriodId idInSource = id.copyWithPeriodUid(getChildPeriodUid(holder, id.periodUid)); mediaPeriod.createPeriod(idInSource); } 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); }
ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHolder> { @Override public final MediaPeriod createPeriod( MediaPeriodId id, Allocator allocator, long startPositionUs) { Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid); MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid); if (holder == null) { holder = new MediaSourceHolder(new DummyMediaSource()); holder.hasStartedPreparing = true; } DeferredMediaPeriod mediaPeriod = new DeferredMediaPeriod(holder.mediaSource, id, allocator, startPositionUs); mediaSourceByMediaPeriod.put(mediaPeriod, holder); holder.activeMediaPeriods.add(mediaPeriod); if (!holder.hasStartedPreparing) { holder.hasStartedPreparing = true; prepareChildSource(holder, holder.mediaSource); } else if (holder.isPrepared) { MediaPeriodId idInSource = id.copyWithPeriodUid(getChildPeriodUid(holder, id.periodUid)); mediaPeriod.createPeriod(idInSource); } 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); final synchronized void addMediaSource(MediaSource mediaSource); final synchronized void addMediaSource(
      MediaSource mediaSource, Handler handler, Runnable onCompletionAction); final synchronized void addMediaSource(int index, MediaSource mediaSource); final synchronized void addMediaSource(
      int index, MediaSource mediaSource, Handler handler, Runnable onCompletionAction); final synchronized void addMediaSources(Collection<MediaSource> mediaSources); final synchronized void addMediaSources(
      Collection<MediaSource> mediaSources, Handler handler, Runnable onCompletionAction); final synchronized void addMediaSources(int index, Collection<MediaSource> mediaSources); final synchronized void addMediaSources(
      int index,
      Collection<MediaSource> mediaSources,
      Handler handler,
      Runnable onCompletionAction); final synchronized void removeMediaSource(int index); final synchronized void removeMediaSource(
      int index, Handler handler, Runnable onCompletionAction); final synchronized void removeMediaSourceRange(int fromIndex, int toIndex); final synchronized void removeMediaSourceRange(
      int fromIndex, int toIndex, Handler handler, Runnable onCompletionAction); final synchronized void moveMediaSource(int currentIndex, int newIndex); final synchronized void moveMediaSource(
      int currentIndex, int newIndex, Handler handler, Runnable onCompletionAction); final synchronized void clear(); final synchronized void clear(Handler handler, Runnable onCompletionAction); final synchronized int getSize(); final synchronized MediaSource getMediaSource(int index); final synchronized void setShuffleOrder(ShuffleOrder shuffleOrder); final synchronized void setShuffleOrder(
      ShuffleOrder shuffleOrder, Handler handler, Runnable onCompletionAction); @Override @Nullable Object getTag(); @Override final synchronized void prepareSourceInternal(
      @Nullable TransferListener mediaTransferListener); @Override @SuppressWarnings("MissingSuperCall") void maybeThrowSourceInfoRefreshError(); @Override final MediaPeriod createPeriod(
      MediaPeriodId id, Allocator allocator, long startPositionUs); @Override final void releasePeriod(MediaPeriod mediaPeriod); @Override final synchronized void releaseSourceInternal(); }
ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHolder> { @Override public final MediaPeriod createPeriod( MediaPeriodId id, Allocator allocator, long startPositionUs) { Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid); MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid); if (holder == null) { holder = new MediaSourceHolder(new DummyMediaSource()); holder.hasStartedPreparing = true; } DeferredMediaPeriod mediaPeriod = new DeferredMediaPeriod(holder.mediaSource, id, allocator, startPositionUs); mediaSourceByMediaPeriod.put(mediaPeriod, holder); holder.activeMediaPeriods.add(mediaPeriod); if (!holder.hasStartedPreparing) { holder.hasStartedPreparing = true; prepareChildSource(holder, holder.mediaSource); } else if (holder.isPrepared) { MediaPeriodId idInSource = id.copyWithPeriodUid(getChildPeriodUid(holder, id.periodUid)); mediaPeriod.createPeriod(idInSource); } 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); final synchronized void addMediaSource(MediaSource mediaSource); final synchronized void addMediaSource(
      MediaSource mediaSource, Handler handler, Runnable onCompletionAction); final synchronized void addMediaSource(int index, MediaSource mediaSource); final synchronized void addMediaSource(
      int index, MediaSource mediaSource, Handler handler, Runnable onCompletionAction); final synchronized void addMediaSources(Collection<MediaSource> mediaSources); final synchronized void addMediaSources(
      Collection<MediaSource> mediaSources, Handler handler, Runnable onCompletionAction); final synchronized void addMediaSources(int index, Collection<MediaSource> mediaSources); final synchronized void addMediaSources(
      int index,
      Collection<MediaSource> mediaSources,
      Handler handler,
      Runnable onCompletionAction); final synchronized void removeMediaSource(int index); final synchronized void removeMediaSource(
      int index, Handler handler, Runnable onCompletionAction); final synchronized void removeMediaSourceRange(int fromIndex, int toIndex); final synchronized void removeMediaSourceRange(
      int fromIndex, int toIndex, Handler handler, Runnable onCompletionAction); final synchronized void moveMediaSource(int currentIndex, int newIndex); final synchronized void moveMediaSource(
      int currentIndex, int newIndex, Handler handler, Runnable onCompletionAction); final synchronized void clear(); final synchronized void clear(Handler handler, Runnable onCompletionAction); final synchronized int getSize(); final synchronized MediaSource getMediaSource(int index); final synchronized void setShuffleOrder(ShuffleOrder shuffleOrder); final synchronized void setShuffleOrder(
      ShuffleOrder shuffleOrder, Handler handler, Runnable onCompletionAction); @Override @Nullable Object getTag(); @Override final synchronized void prepareSourceInternal(
      @Nullable TransferListener mediaTransferListener); @Override @SuppressWarnings("MissingSuperCall") void maybeThrowSourceInfoRefreshError(); @Override final MediaPeriod createPeriod(
      MediaPeriodId id, Allocator allocator, long startPositionUs); @Override final void releasePeriod(MediaPeriod mediaPeriod); @Override final synchronized void releaseSourceInternal();  }