use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class MediaPeriodQueueTest method resolveMediaPeriodIdForAdsAfterPeriodPositionChange_beforeAdPositionInSinglePeriodTimeline_seekNotAdjusted.
@Test
public void resolveMediaPeriodIdForAdsAfterPeriodPositionChange_beforeAdPositionInSinglePeriodTimeline_seekNotAdjusted() {
long adPositionUs = DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 10_000;
AdPlaybackState adPlaybackState = new AdPlaybackState("adsId", adPositionUs).withAdDurationsUs(/* adGroupIndex= */
0, 5_000);
Object windowUid = new Object();
FakeTimeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
windowUid, /* isSeekable= */
true, /* isDynamic= */
false, TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US, adPlaybackState));
MediaPeriodId mediaPeriodId = mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange(timeline, new Pair<>(windowUid, 0), adPositionUs - 1);
assertThat(mediaPeriodId.periodUid).isEqualTo(new Pair<>(windowUid, 0));
assertThat(mediaPeriodId.adGroupIndex).isEqualTo(-1);
assertThat(mediaPeriodId.adIndexInAdGroup).isEqualTo(-1);
assertThat(mediaPeriodId.nextAdGroupIndex).isEqualTo(0);
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class MediaPeriodQueueTest method setupAdTimeline.
private void setupAdTimeline(long... adGroupTimesUs) {
adPlaybackState = new AdPlaybackState(/* adsId= */
new Object(), adGroupTimesUs).withContentDurationUs(CONTENT_DURATION_US);
SinglePeriodAdTimeline adTimeline = new SinglePeriodAdTimeline(CONTENT_TIMELINE, adPlaybackState);
setupTimeline(adTimeline);
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class MediaPeriodQueueTest method resolveMediaPeriodIdForAdsAfterPeriodPositionChange_toAdPositionInSinglePeriodTimeline_resolvesToAd.
@Test
public void resolveMediaPeriodIdForAdsAfterPeriodPositionChange_toAdPositionInSinglePeriodTimeline_resolvesToAd() {
long adPositionUs = DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 10_000;
AdPlaybackState adPlaybackState = new AdPlaybackState("adsId", adPositionUs);
adPlaybackState = adPlaybackState.withAdDurationsUs(/* adGroupIndex= */
0, 5_000);
Object windowUid = new Object();
FakeTimeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
windowUid, /* isSeekable= */
true, /* isDynamic= */
false, TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US, adPlaybackState));
MediaPeriodId mediaPeriodId = mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange(timeline, /* periodUid= */
new Pair<>(windowUid, 0), adPositionUs);
assertThat(mediaPeriodId.periodUid).isEqualTo(new Pair<>(windowUid, 0));
assertThat(mediaPeriodId.adGroupIndex).isEqualTo(0);
assertThat(mediaPeriodId.adIndexInAdGroup).isEqualTo(0);
assertThat(mediaPeriodId.nextAdGroupIndex).isEqualTo(-1);
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class DefaultPlaybackSessionManagerTest method updateSessions_withNewAd_afterDiscontinuitiesFromContentToAdAndBack_doesNotActivateNewAd.
@Test
public void updateSessions_withNewAd_afterDiscontinuitiesFromContentToAdAndBack_doesNotActivateNewAd() {
Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
10 * C.MICROS_PER_SECOND, new AdPlaybackState(/* adsId= */
new Object(), /* adGroupTimesUs=... */
2 * C.MICROS_PER_SECOND, 5 * C.MICROS_PER_SECOND).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).withAdCount(/* adGroupIndex= */
1, /* adCount= */
1)));
EventTime adEventTime1 = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
0));
EventTime adEventTime2 = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* adGroupIndex= */
1, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
0));
EventTime contentEventTime1 = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0, /* nextAdGroupIndex= */
0));
EventTime contentEventTime2 = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0, /* nextAdGroupIndex= */
1));
sessionManager.updateSessionsWithTimelineChange(contentEventTime1);
sessionManager.updateSessions(adEventTime1);
sessionManager.updateSessionsWithDiscontinuity(adEventTime1, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
sessionManager.updateSessionsWithDiscontinuity(contentEventTime2, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
String adSessionId2 = sessionManager.getSessionForMediaPeriodId(adTimeline, adEventTime2.mediaPeriodId);
sessionManager.updateSessions(adEventTime2);
verify(mockListener, never()).onSessionActive(any(), eq(adSessionId2));
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class ServerSideAdInsertionMediaSourceTest method timeline_missingAdPlaybackStateByPeriodUid_isAssertedAndThrows.
@Test
public void timeline_missingAdPlaybackStateByPeriodUid_isAssertedAndThrows() {
ServerSideAdInsertionMediaSource mediaSource = new ServerSideAdInsertionMediaSource(new FakeMediaSource(), /* adPlaybackStateUpdater= */
null);
// The map of adPlaybackStates does not contain a valid period UID as key.
mediaSource.setAdPlaybackStates(ImmutableMap.of(new Object(), new AdPlaybackState(/* adsId= */
new Object())));
Assert.assertThrows(IllegalStateException.class, () -> mediaSource.prepareSource((source, timeline) -> {
/* Do nothing. */
}, /* mediaTransferListener= */
null, PlayerId.UNSET));
}
Aggregations