currentPeriodId.windowSequenceNumber); int adIndexInAdGroup = period.getFirstAdIndexToPlay(nextAdGroupIndex); return !period.isAdAvailable(nextAdGroupIndex, adIndexInAdGroup) ? null return null; int adIndexInAdGroup = period.getFirstAdIndexToPlay(adGroupIndex); if (!period.isAdAvailable(adGroupIndex, adIndexInAdGroup)) { return null;
/** * Resolves the specified timeline period and position to a {@link MediaPeriodId} that should be * played, returning an identifier for an ad group if one needs to be played before the specified * position, or an identifier for a content media period if not. * * @param periodUid The uid of the timeline period to play. * @param positionUs The next content position in the period to play. * @param windowSequenceNumber The sequence number of the window in the buffered sequence of * windows this period is part of. * @return The identifier for the first media period to play, taking into account unplayed ads. */ private MediaPeriodId resolveMediaPeriodIdForAds( Object periodUid, long positionUs, long windowSequenceNumber) { timeline.getPeriodByUid(periodUid, period); int adGroupIndex = period.getAdGroupIndexForPositionUs(positionUs); if (adGroupIndex == C.INDEX_UNSET) { int nextAdGroupIndex = period.getAdGroupIndexAfterPositionUs(positionUs); long endPositionUs = nextAdGroupIndex == C.INDEX_UNSET ? C.TIME_END_OF_SOURCE : period.getAdGroupTimeUs(nextAdGroupIndex); return new MediaPeriodId(periodUid, windowSequenceNumber, endPositionUs); } else { int adIndexInAdGroup = period.getFirstAdIndexToPlay(adGroupIndex); return new MediaPeriodId(periodUid, adGroupIndex, adIndexInAdGroup, windowSequenceNumber); } }
private MediaPeriodInfo getMediaPeriodInfoForAd( Object periodUid, int adGroupIndex, int adIndexInAdGroup, long contentPositionUs, long windowSequenceNumber) { MediaPeriodId id = new MediaPeriodId(periodUid, adGroupIndex, adIndexInAdGroup, windowSequenceNumber); boolean isLastInPeriod = isLastInPeriod(id); boolean isLastInTimeline = isLastInTimeline(id, isLastInPeriod); long durationUs = timeline .getPeriodByUid(id.periodUid, period) .getAdDurationUs(id.adGroupIndex, id.adIndexInAdGroup); long startPositionUs = adIndexInAdGroup == period.getFirstAdIndexToPlay(adGroupIndex) ? period.getAdResumePositionUs() : 0; return new MediaPeriodInfo( id, startPositionUs, contentPositionUs, durationUs, isLastInPeriod, isLastInTimeline); }
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); }