Search in sources :

Example 21 with TimelineWindowDefinition

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition 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 22 with TimelineWindowDefinition

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.

the class ExoPlayerTest method removeMediaItem.

@Test
public void removeMediaItem() throws Exception {
    TimelineWindowDefinition firstWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    1, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(10000));
    TimelineWindowDefinition secondWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    2, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(10000));
    TimelineWindowDefinition thirdWindowDefinition = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    3, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(10000));
    Timeline timeline1 = new FakeTimeline(firstWindowDefinition);
    Timeline timeline2 = new FakeTimeline(secondWindowDefinition);
    Timeline timeline3 = new FakeTimeline(thirdWindowDefinition);
    MediaSource mediaSource1 = new FakeMediaSource(timeline1);
    MediaSource mediaSource2 = new FakeMediaSource(timeline2);
    MediaSource mediaSource3 = new FakeMediaSource(timeline3);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).removeMediaItem(/* index= */
    0).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource1, mediaSource2, mediaSource3).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    Timeline expectedPlaceholderTimeline = new FakeTimeline(TimelineWindowDefinition.createPlaceholder(/* tag= */
    1), TimelineWindowDefinition.createPlaceholder(/* tag= */
    2), TimelineWindowDefinition.createPlaceholder(/* tag= */
    3));
    Timeline expectedRealTimeline = new FakeTimeline(firstWindowDefinition, secondWindowDefinition, thirdWindowDefinition);
    Timeline expectedRealTimelineAfterRemove = new FakeTimeline(secondWindowDefinition, thirdWindowDefinition);
    exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
    exoPlayerTestRunner.assertTimelinesSame(expectedPlaceholderTimeline, expectedRealTimeline, expectedRealTimelineAfterRemove);
}
Also used : NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 23 with TimelineWindowDefinition

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition 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 24 with TimelineWindowDefinition

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.

the class DefaultPlaybackSessionManagerTest method belongsToSession_withAd_returnsFalse.

@Test
public void belongsToSession_withAd_returnsFalse() {
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    new Object(), /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    10_000_000, FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    1, /* adGroupTimesUs... */
    0)));
    MediaPeriodId contentMediaPeriodId = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0);
    MediaPeriodId adMediaPeriodId = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0), /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    1);
    EventTime contentEventTime = createEventTime(timeline, /* windowIndex= */
    0, contentMediaPeriodId);
    EventTime adEventTime = createEventTime(timeline, /* windowIndex= */
    0, adMediaPeriodId);
    sessionManager.updateSessions(contentEventTime);
    sessionManager.updateSessions(adEventTime);
    ArgumentCaptor<String> sessionId1 = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> sessionId2 = ArgumentCaptor.forClass(String.class);
    verify(mockListener).onSessionCreated(eq(contentEventTime), sessionId1.capture());
    verify(mockListener).onSessionCreated(eq(adEventTime), sessionId2.capture());
    assertThat(sessionManager.belongsToSession(adEventTime, sessionId1.getValue())).isFalse();
    assertThat(sessionManager.belongsToSession(contentEventTime, sessionId2.getValue())).isFalse();
    assertThat(sessionManager.belongsToSession(adEventTime, sessionId2.getValue())).isTrue();
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) 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 25 with TimelineWindowDefinition

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.

the class DefaultPlaybackSessionManagerTest method timelineUpdate_toNewMediaWithWindowIndexOnly_finishesOtherSessions.

@Test
public void timelineUpdate_toNewMediaWithWindowIndexOnly_finishesOtherSessions() {
    Timeline firstTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    1000), new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    2000), new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    3000));
    EventTime eventTimeFirstTimelineWithPeriodId = createEventTime(firstTimeline, /* windowIndex= */
    0, new MediaPeriodId(firstTimeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0));
    EventTime eventTimeFirstTimelineWindowOnly1 = createEventTime(firstTimeline, /* windowIndex= */
    1, /* mediaPeriodId= */
    null);
    EventTime eventTimeFirstTimelineWindowOnly2 = createEventTime(firstTimeline, /* windowIndex= */
    2, /* mediaPeriodId= */
    null);
    Timeline secondTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    2000), new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    4000));
    EventTime eventTimeSecondTimeline = createEventTime(secondTimeline, /* windowIndex= */
    0, /* mediaPeriodId= */
    null);
    sessionManager.updateSessionsWithTimelineChange(eventTimeFirstTimelineWithPeriodId);
    sessionManager.updateSessions(eventTimeFirstTimelineWindowOnly1);
    sessionManager.updateSessions(eventTimeFirstTimelineWindowOnly2);
    sessionManager.updateSessionsWithTimelineChange(eventTimeSecondTimeline);
    InOrder inOrder = inOrder(mockListener);
    ArgumentCaptor<String> firstId = ArgumentCaptor.forClass(String.class);
    inOrder.verify(mockListener).onSessionCreated(eq(eventTimeFirstTimelineWithPeriodId), firstId.capture());
    inOrder.verify(mockListener).onSessionActive(eventTimeFirstTimelineWithPeriodId, firstId.getValue());
    ArgumentCaptor<String> secondId = ArgumentCaptor.forClass(String.class);
    inOrder.verify(mockListener).onSessionCreated(eq(eventTimeFirstTimelineWindowOnly1), secondId.capture());
    ArgumentCaptor<String> thirdId = ArgumentCaptor.forClass(String.class);
    inOrder.verify(mockListener).onSessionCreated(eq(eventTimeFirstTimelineWindowOnly2), thirdId.capture());
    // The sessions may finish at the same time, so the order of these two callbacks is undefined.
    ArgumentCaptor<String> finishedSessions = ArgumentCaptor.forClass(String.class);
    inOrder.verify(mockListener, times(2)).onSessionFinished(eq(eventTimeSecondTimeline), finishedSessions.capture(), /* automaticTransitionToNextPlayback= */
    eq(false));
    assertThat(finishedSessions.getAllValues()).containsExactly(firstId.getValue(), thirdId.getValue());
    inOrder.verify(mockListener).onSessionActive(eventTimeSecondTimeline, secondId.getValue());
    inOrder.verifyNoMoreInteractions();
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) InOrder(org.mockito.InOrder) 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)

Aggregations

Test (org.junit.Test)103 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)101 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)101 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)79 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)69 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)61 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)61 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)35 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)30 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)28 Listener (com.google.android.exoplayer2.Player.Listener)27 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)26 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)22 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)20 Timeline (com.google.android.exoplayer2.Timeline)19 MediaSource (com.google.android.exoplayer2.source.MediaSource)19 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)18 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)16 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)16 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)16