use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US in project ExoPlayer by google.
the class MediaPeriodQueueTest method resolveMediaPeriodIdForAdsAfterPeriodPositionChange_behindAdPositionInSinglePeriodTimeline_resolvesToAd.
@Test
public void resolveMediaPeriodIdForAdsAfterPeriodPositionChange_behindAdPositionInSinglePeriodTimeline_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 + 1);
assertThat(mediaPeriodId.adGroupIndex).isEqualTo(0);
assertThat(mediaPeriodId.adIndexInAdGroup).isEqualTo(0);
assertThat(mediaPeriodId.nextAdGroupIndex).isEqualTo(-1);
assertThat(mediaPeriodId.periodUid).isEqualTo(new Pair<>(windowUid, 0));
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US 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.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US 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.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US in project ExoPlayer by google.
the class MediaPeriodQueueTest method getNextMediaPeriodInfo_inMultiPeriodWindow_returnsCorrectMediaPeriodInfos.
@Test
public void getNextMediaPeriodInfo_inMultiPeriodWindow_returnsCorrectMediaPeriodInfos() {
setupTimeline(new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
2, /* id= */
new Object(), /* isSeekable= */
false, /* isDynamic= */
false, /* durationUs= */
2 * CONTENT_DURATION_US)));
assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(/* periodUid= */
playbackInfo.timeline.getUidOfPeriod(/* periodIndex= */
0), /* startPositionUs= */
0, /* requestedContentPositionUs= */
C.TIME_UNSET, /* endPositionUs= */
C.TIME_UNSET, /* durationUs= */
CONTENT_DURATION_US + DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, /* isFollowedByTransitionToSameStream= */
false, /* isLastInPeriod= */
true, /* isLastInWindow= */
false, /* nextAdGroupIndex= */
C.INDEX_UNSET);
advance();
assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(/* periodUid= */
playbackInfo.timeline.getUidOfPeriod(/* periodIndex= */
1), /* startPositionUs= */
0, /* requestedContentPositionUs= */
0, /* endPositionUs= */
C.TIME_UNSET, /* durationUs= */
CONTENT_DURATION_US, /* isFollowedByTransitionToSameStream= */
false, /* isLastInPeriod= */
true, /* isLastInWindow= */
true, /* nextAdGroupIndex= */
C.INDEX_UNSET);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US in project ExoPlayer by google.
the class ExoPlayerTest method play_playedSSAIPreMidPostRollsSinglePeriodWindow_noDiscontinuities.
@Test
public void play_playedSSAIPreMidPostRollsSinglePeriodWindow_noDiscontinuities() throws Exception {
AdPlaybackState adPlaybackState = addAdGroupToAdPlaybackState(new AdPlaybackState("adsId"), /* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
C.MICROS_PER_SECOND);
adPlaybackState = addAdGroupToAdPlaybackState(adPlaybackState, /* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (3 * C.MICROS_PER_SECOND), /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
C.MICROS_PER_SECOND);
adPlaybackState = addAdGroupToAdPlaybackState(adPlaybackState, /* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (5 * C.MICROS_PER_SECOND), /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
C.MICROS_PER_SECOND);
adPlaybackState = addAdGroupToAdPlaybackState(adPlaybackState, /* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (9 * C.MICROS_PER_SECOND), /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
C.MICROS_PER_SECOND);
adPlaybackState = adPlaybackState.withPlayedAd(/* adGroupIndex= */
0, /* adIndexInAdGroup+ */
0);
adPlaybackState = adPlaybackState.withPlayedAd(/* adGroupIndex= */
1, /* adIndexInAdGroup+ */
0);
adPlaybackState = adPlaybackState.withPlayedAd(/* adGroupIndex= */
2, /* adIndexInAdGroup+ */
0);
adPlaybackState = adPlaybackState.withPlayedAd(/* adGroupIndex= */
3, /* adIndexInAdGroup+ */
0);
FakeTimeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, "windowId", /* isSeekable= */
true, /* isDynamic= */
false, /* isLive= */
false, /* isPlaceholder= */
false, /* durationUs= */
DEFAULT_WINDOW_DURATION_US, /* defaultPositionUs= */
0, /* windowOffsetInFirstPeriodUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, /* adPlaybackStates= */
ImmutableList.of(adPlaybackState), MediaItem.EMPTY));
Listener listener = mock(Listener.class);
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.addListener(listener);
AtomicReference<ServerSideAdInsertionMediaSource> sourceReference = new AtomicReference<>();
sourceReference.set(new ServerSideAdInsertionMediaSource(new FakeMediaSource(adTimeline, ExoPlayerTestRunner.AUDIO_FORMAT), contentTimeline -> {
sourceReference.get().setAdPlaybackStates(adTimeline.getAdPlaybackStates(/* windowIndex= */
0));
return true;
}));
player.setMediaSource(sourceReference.get());
player.prepare();
player.play();
runUntilPlaybackState(player, Player.STATE_ENDED);
long finalPositionMs = player.getCurrentPosition();
player.release();
assertThat(finalPositionMs).isEqualTo(6000);
verify(listener, never()).onPositionDiscontinuity(any(), any(), anyInt());
ArgumentCaptor<Integer> playbackStateCaptor = ArgumentCaptor.forClass(Integer.class);
verify(listener, times(3)).onPlaybackStateChanged(playbackStateCaptor.capture());
assertThat(playbackStateCaptor.getAllValues()).containsExactly(2, 3, 4).inOrder();
}
Aggregations