private void assertCompletedAllMediaPeriodLoads(Timeline timeline) { Timeline.Period period = new Timeline.Period(); Timeline.Window window = new Timeline.Window(); ArrayList<MediaPeriodId> expectedMediaPeriodIds = new ArrayList<>(); for (int windowIndex = 0; windowIndex < timeline.getWindowCount(); windowIndex++) { timeline.getWindow(windowIndex, window); for (int periodIndex = window.firstPeriodIndex; periodIndex <= window.lastPeriodIndex; periodIndex++) { timeline.getPeriod(periodIndex, period); Object periodUid = timeline.getUidOfPeriod(periodIndex); expectedMediaPeriodIds.add(new MediaPeriodId(periodUid, windowIndex)); for (int adGroupIndex = 0; adGroupIndex < period.getAdGroupCount(); adGroupIndex++) { for (int adIndex = 0; adIndex < period.getAdCountInAdGroup(adGroupIndex); adIndex++) { expectedMediaPeriodIds.add( new MediaPeriodId(periodUid, adGroupIndex, adIndex, windowIndex)); } } } } testRunner.assertCompletedMediaPeriodLoads( expectedMediaPeriodIds.toArray(new MediaPeriodId[0])); }
if (currentPeriodId.isAd()) { int adGroupIndex = currentPeriodId.adGroupIndex; int adCountInCurrentAdGroup = period.getAdCountInAdGroup(adGroupIndex); if (adCountInCurrentAdGroup == C.LENGTH_UNSET) { return null;
private boolean isLastInPeriod(MediaPeriodId id) { int adGroupCount = timeline.getPeriodByUid(id.periodUid, period).getAdGroupCount(); if (adGroupCount == 0) { return true; } int lastAdGroupIndex = adGroupCount - 1; boolean isAd = id.isAd(); if (period.getAdGroupTimeUs(lastAdGroupIndex) != C.TIME_END_OF_SOURCE) { // There's no postroll ad. return !isAd && id.endPositionUs == C.TIME_END_OF_SOURCE; } int postrollAdCount = period.getAdCountInAdGroup(lastAdGroupIndex); if (postrollAdCount == C.LENGTH_UNSET) { // We won't know if this is the last ad until we know how many postroll ads there are. return false; } boolean isLastAd = isAd && id.adGroupIndex == lastAdGroupIndex && id.adIndexInAdGroup == postrollAdCount - 1; return isLastAd || (!isAd && period.getFirstAdIndexToPlay(lastAdGroupIndex) == postrollAdCount); }
/** * Creates and releases all periods (including ad periods) defined in the last timeline to be * returned from {@link #prepareSource()}, {@link #assertTimelineChange()} or {@link * #assertTimelineChangeBlocking()}. The {@link MediaPeriodId#windowSequenceNumber} is set to the * index of the window. */ public void assertPrepareAndReleaseAllPeriods() throws InterruptedException { Timeline.Period period = new Timeline.Period(); for (int i = 0; i < timeline.getPeriodCount(); i++) { timeline.getPeriod(i, period, /* setIds= */ true); assertPrepareAndReleasePeriod(new MediaPeriodId(period.uid, period.windowIndex)); for (int adGroupIndex = 0; adGroupIndex < period.getAdGroupCount(); adGroupIndex++) { for (int adIndex = 0; adIndex < period.getAdCountInAdGroup(adGroupIndex); adIndex++) { assertPrepareAndReleasePeriod( new MediaPeriodId(period.uid, adGroupIndex, adIndex, period.windowIndex)); } } } }
/** * Creates and releases all periods (including ad periods) defined in the last timeline to be * returned from {@link #prepareSource()}, {@link #assertTimelineChange()} or {@link * #assertTimelineChangeBlocking()}. The {@link MediaPeriodId#windowSequenceNumber} is set to the * index of the window. */ public void assertPrepareAndReleaseAllPeriods() throws InterruptedException { Timeline.Period period = new Timeline.Period(); for (int i = 0; i < timeline.getPeriodCount(); i++) { timeline.getPeriod(i, period, /* setIds= */ true); assertPrepareAndReleasePeriod(new MediaPeriodId(period.uid, period.windowIndex)); for (int adGroupIndex = 0; adGroupIndex < period.getAdGroupCount(); adGroupIndex++) { for (int adIndex = 0; adIndex < period.getAdCountInAdGroup(adGroupIndex); adIndex++) { assertPrepareAndReleasePeriod( new MediaPeriodId(period.uid, adGroupIndex, adIndex, period.windowIndex)); } } } }