MediaPeriodQueue { public @Nullable MediaPeriodInfo getNextMediaPeriodInfo( long rendererPositionUs, PlaybackInfo playbackInfo) { return loading == null ? getFirstMediaPeriodInfo(playbackInfo) : getFollowingMediaPeriodInfo(loading, rendererPositionUs); } MediaPeriodQueue(); void setTimeline(Timeline timeline); boolean updateRepeatMode(@RepeatMode int repeatMode); boolean updateShuffleModeEnabled(boolean shuffleModeEnabled); boolean isLoading(MediaPeriod mediaPeriod); void reevaluateBuffer(long rendererPositionUs); boolean shouldLoadNextMediaPeriod(); @Nullable MediaPeriodInfo getNextMediaPeriodInfo(
      long rendererPositionUs, PlaybackInfo playbackInfo); MediaPeriodHolder enqueueNextMediaPeriodHolder(
      RendererCapabilities[] rendererCapabilities,
      TrackSelector trackSelector,
      Allocator allocator,
      MediaSource mediaSource,
      MediaPeriodInfo info,
      TrackSelectorResult emptyTrackSelectorResult); @Nullable MediaPeriodHolder getLoadingPeriod(); @Nullable MediaPeriodHolder getPlayingPeriod(); @Nullable MediaPeriodHolder getReadingPeriod(); MediaPeriodHolder advanceReadingPeriod(); @Nullable MediaPeriodHolder advancePlayingPeriod(); boolean removeAfter(MediaPeriodHolder mediaPeriodHolder); void clear(boolean keepFrontPeriodUid); boolean updateQueuedPeriods(long rendererPositionUs, long maxRendererReadPositionUs); MediaPeriodInfo getUpdatedMediaPeriodInfo(MediaPeriodInfo info); MediaPeriodId resolveMediaPeriodIdForAds(Object periodUid, long positionUs);  }
@Test public void getNextMediaPeriodInfo_withMidrollAds_returnsCorrectMediaPeriodInfos() { setupTimeline( 0, FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US); assertGetNextMediaPeriodInfoReturnsContentMediaPeriod( 0, FIRST_AD_START_TIME_US, FIRST_AD_START_TIME_US, false, 0); advance(); assertNull(getNextMediaPeriodInfo()); setAdGroupLoaded( 0); assertNextMediaPeriodInfoIsAd( 0, FIRST_AD_START_TIME_US); advance(); assertGetNextMediaPeriodInfoReturnsContentMediaPeriod( FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US, SECOND_AD_START_TIME_US, false, 1); advance(); setAdGroupLoaded( 1); assertNextMediaPeriodInfoIsAd( 1, SECOND_AD_START_TIME_US); advance(); assertGetNextMediaPeriodInfoReturnsContentMediaPeriod( SECOND_AD_START_TIME_US, C.TIME_UNSET, CONTENT_DURATION_US, true, C.INDEX_UNSET); }