Search in sources :

Example 41 with AdPlaybackState

use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.

the class ExoPlayerTest method seekTo_seekOverMidRoll_callsOnDiscontinuityCorrectly.

@Test
public void seekTo_seekOverMidRoll_callsOnDiscontinuityCorrectly() throws Exception {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    Player.Listener listener = mock(Player.Listener.class);
    player.addListener(listener);
    AdPlaybackState adPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    1, /* adGroupTimesUs...= */
    2 * C.MICROS_PER_SECOND);
    TimelineWindowDefinition adTimeline = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs= */
    10 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
    0, /* windowOffsetInFirstPeriodUs= */
    0, adPlaybackState);
    player.setMediaSource(new FakeMediaSource(new FakeTimeline(adTimeline)));
    player.prepare();
    TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
    0, /* positionMs= */
    1000);
    player.seekTo(/* positionMs= */
    8_000);
    player.play();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
    ArgumentCaptor<Player.PositionInfo> oldPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
    ArgumentCaptor<Player.PositionInfo> newPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
    verify(listener).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_SEEK));
    verify(listener).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT));
    verify(listener).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    verify(listener, never()).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_REMOVE));
    verify(listener, never()).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_SKIP));
    List<Player.PositionInfo> oldPositions = oldPosition.getAllValues();
    List<Player.PositionInfo> newPositions = newPosition.getAllValues();
    // SEEK behind mid roll
    assertThat(oldPositions.get(0).mediaItemIndex).isEqualTo(0);
    assertThat(oldPositions.get(0).positionMs).isIn(Range.closed(980L, 1_000L));
    assertThat(oldPositions.get(0).contentPositionMs).isIn(Range.closed(980L, 1_000L));
    assertThat(oldPositions.get(0).adGroupIndex).isEqualTo(-1);
    assertThat(oldPositions.get(0).adIndexInAdGroup).isEqualTo(-1);
    assertThat(newPositions.get(0).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(0).positionMs).isEqualTo(8_000);
    assertThat(newPositions.get(0).contentPositionMs).isEqualTo(8_000);
    assertThat(newPositions.get(0).adGroupIndex).isEqualTo(-1);
    assertThat(newPositions.get(0).adIndexInAdGroup).isEqualTo(-1);
    // SEEK_ADJUSTMENT back to ad
    assertThat(oldPositions.get(1).mediaItemIndex).isEqualTo(0);
    assertThat(oldPositions.get(1).positionMs).isEqualTo(8_000);
    assertThat(oldPositions.get(1).contentPositionMs).isEqualTo(8_000);
    assertThat(oldPositions.get(1).adGroupIndex).isEqualTo(-1);
    assertThat(oldPositions.get(1).adIndexInAdGroup).isEqualTo(-1);
    assertThat(newPositions.get(1).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(1).positionMs).isEqualTo(0);
    assertThat(newPositions.get(1).contentPositionMs).isEqualTo(8000);
    assertThat(newPositions.get(1).adGroupIndex).isEqualTo(0);
    assertThat(newPositions.get(1).adIndexInAdGroup).isEqualTo(0);
    // AUTO_TRANSITION back to content
    assertThat(oldPositions.get(2).mediaItemIndex).isEqualTo(0);
    assertThat(oldPositions.get(2).positionMs).isEqualTo(5_000);
    assertThat(oldPositions.get(2).contentPositionMs).isEqualTo(8_000);
    assertThat(oldPositions.get(2).adGroupIndex).isEqualTo(0);
    assertThat(oldPositions.get(2).adIndexInAdGroup).isEqualTo(0);
    assertThat(newPositions.get(2).mediaItemIndex).isEqualTo(0);
    assertThat(newPositions.get(2).positionMs).isEqualTo(8_000);
    assertThat(newPositions.get(2).contentPositionMs).isEqualTo(8_000);
    assertThat(newPositions.get(2).adGroupIndex).isEqualTo(-1);
    assertThat(newPositions.get(2).adIndexInAdGroup).isEqualTo(-1);
    player.release();
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) PositionInfo(com.google.android.exoplayer2.Player.PositionInfo) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 42 with AdPlaybackState

use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.

the class ExoPlayerTest method adGroupWithLoadError_noFurtherAdGroup_isSkipped.

@Test
public void adGroupWithLoadError_noFurtherAdGroup_isSkipped() throws Exception {
    AdPlaybackState initialAdPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    1, /* adGroupTimesUs...= */
    TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 5 * C.MICROS_PER_SECOND);
    Timeline fakeTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs= */
    10 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
    0, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, initialAdPlaybackState));
    AdPlaybackState errorAdPlaybackState = initialAdPlaybackState.withAdLoadError(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0);
    final Timeline adErrorTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs= */
    10 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
    0, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, errorAdPlaybackState));
    final FakeMediaSource fakeMediaSource = new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT);
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    Player.Listener mockListener = mock(Player.Listener.class);
    player.addListener(mockListener);
    player.setMediaSource(fakeMediaSource);
    player.prepare();
    runUntilPlaybackState(player, Player.STATE_READY);
    fakeMediaSource.setNewSourceInfo(adErrorTimeline);
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    Timeline.Window window = player.getCurrentTimeline().getWindow(/* windowIndex= */
    0, new Timeline.Window());
    Timeline.Period period = player.getCurrentTimeline().getPeriod(/* periodIndex= */
    0, new Timeline.Period(), /* setIds= */
    true);
    player.release();
    // Content to content transition is ignored.
    verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Window(com.google.android.exoplayer2.Timeline.Window) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 43 with AdPlaybackState

use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.

the class DefaultPlaybackSessionManagerTest method positionDiscontinuity_fromAdToContent_finishesAd.

@Test
public void positionDiscontinuity_fromAdToContent_finishesAd() {
    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=... */
    0, 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 contentEventTimeDuringPreroll = createEventTime(adTimeline, /* windowIndex= */
    0, /* eventMediaPeriodId= */
    new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    0), /* currentMediaPeriodId= */
    new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
    0), /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    0));
    EventTime contentEventTimeBetweenAds = createEventTime(adTimeline, /* windowIndex= */
    0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    1));
    sessionManager.updateSessionsWithTimelineChange(adEventTime1);
    sessionManager.updateSessions(adEventTime2);
    String adSessionId1 = sessionManager.getSessionForMediaPeriodId(adTimeline, adEventTime1.mediaPeriodId);
    String contentSessionId = sessionManager.getSessionForMediaPeriodId(adTimeline, contentEventTimeDuringPreroll.mediaPeriodId);
    sessionManager.updateSessionsWithDiscontinuity(contentEventTimeBetweenAds, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
    InOrder inOrder = inOrder(mockListener);
    inOrder.verify(mockListener).onSessionCreated(contentEventTimeDuringPreroll, contentSessionId);
    inOrder.verify(mockListener).onSessionCreated(adEventTime1, adSessionId1);
    inOrder.verify(mockListener).onSessionActive(adEventTime1, adSessionId1);
    inOrder.verify(mockListener).onAdPlaybackStarted(adEventTime1, contentSessionId, adSessionId1);
    inOrder.verify(mockListener).onSessionCreated(eq(adEventTime2), anyString());
    inOrder.verify(mockListener).onSessionFinished(contentEventTimeBetweenAds, adSessionId1, /* automaticTransitionToNextPlayback= */
    true);
    inOrder.verify(mockListener).onSessionActive(eq(contentEventTimeBetweenAds), anyString());
    inOrder.verifyNoMoreInteractions();
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) InOrder(org.mockito.InOrder) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 44 with AdPlaybackState

use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.

the class DefaultPlaybackSessionManagerTest method positionDiscontinuity_fromContentToAd_doesNotFinishSessions.

@Test
public void positionDiscontinuity_fromContentToAd_doesNotFinishSessions() {
    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 contentEventTime = createEventTime(adTimeline, /* windowIndex= */
    0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    0));
    sessionManager.updateSessionsWithTimelineChange(contentEventTime);
    sessionManager.updateSessions(adEventTime1);
    sessionManager.updateSessions(adEventTime2);
    sessionManager.updateSessionsWithDiscontinuity(adEventTime1, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
    verify(mockListener, never()).onSessionFinished(any(), anyString(), anyBoolean());
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 45 with AdPlaybackState

use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.

the class DefaultPlaybackSessionManagerTest method timelineUpdate_withContent_doesNotFinishFuturePostrollAd.

@Test
public void timelineUpdate_withContent_doesNotFinishFuturePostrollAd() {
    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=... */
    C.TIME_END_OF_SOURCE).withAdCount(/* adGroupIndex= */
    0, /* adCount= */
    1)));
    EventTime adEventTime = createEventTime(adTimeline, /* windowIndex= */
    0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
    0), /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    0));
    EventTime contentEventTime = createEventTime(adTimeline, /* windowIndex= */
    0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    0));
    sessionManager.updateSessions(contentEventTime);
    sessionManager.updateSessions(adEventTime);
    sessionManager.updateSessionsWithTimelineChange(contentEventTime);
    verify(mockListener, never()).onSessionFinished(any(), anyString(), anyBoolean());
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)89 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)87 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)51 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)35 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)32 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)27 Pair (android.util.Pair)19 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)17 Timeline (com.google.android.exoplayer2.Timeline)15 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)14 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)14 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)13 DefaultMediaSourceFactory (com.google.android.exoplayer2.source.DefaultMediaSourceFactory)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 Listener (com.google.android.exoplayer2.Player.Listener)10 Context (android.content.Context)9 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)9 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)8 SurfaceTexture (android.graphics.SurfaceTexture)7 Surface (android.view.Surface)7