Search in sources :

Example 76 with TimelineWindowDefinition

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition 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);
}
Also used : FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) Test(org.junit.Test)

Example 77 with TimelineWindowDefinition

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition 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));
}
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 78 with TimelineWindowDefinition

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

the class DefaultPlaybackSessionManagerTest method timelineUpdate_resolvesWindowIndices.

@Test
public void timelineUpdate_resolvesWindowIndices() {
    Timeline initialTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    2, /* id= */
    100), new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    200), new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    300));
    EventTime eventForInitialTimelineId100 = createEventTime(initialTimeline, /* windowIndex= */
    0, new MediaPeriodId(initialTimeline.getUidOfPeriod(/* periodIndex= */
    1), /* windowSequenceNumber= */
    0));
    EventTime eventForInitialTimelineId200 = createEventTime(initialTimeline, /* windowIndex= */
    1, new MediaPeriodId(initialTimeline.getUidOfPeriod(/* periodIndex= */
    2), /* windowSequenceNumber= */
    1));
    EventTime eventForInitialTimelineId300 = createEventTime(initialTimeline, /* windowIndex= */
    2, new MediaPeriodId(initialTimeline.getUidOfPeriod(/* periodIndex= */
    3), /* windowSequenceNumber= */
    2));
    sessionManager.updateSessionsWithTimelineChange(eventForInitialTimelineId100);
    sessionManager.updateSessions(eventForInitialTimelineId200);
    sessionManager.updateSessions(eventForInitialTimelineId300);
    String sessionId100 = sessionManager.getSessionForMediaPeriodId(initialTimeline, eventForInitialTimelineId100.mediaPeriodId);
    String sessionId200 = sessionManager.getSessionForMediaPeriodId(initialTimeline, eventForInitialTimelineId200.mediaPeriodId);
    String sessionId300 = sessionManager.getSessionForMediaPeriodId(initialTimeline, eventForInitialTimelineId300.mediaPeriodId);
    Timeline timelineUpdate = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    300), new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    100));
    EventTime eventForTimelineUpdateId100 = createEventTime(timelineUpdate, /* windowIndex= */
    1, new MediaPeriodId(timelineUpdate.getUidOfPeriod(/* periodIndex= */
    1), /* windowSequenceNumber= */
    0));
    EventTime eventForTimelineUpdateId300 = createEventTime(timelineUpdate, /* windowIndex= */
    0, new MediaPeriodId(timelineUpdate.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    2));
    sessionManager.updateSessionsWithTimelineChange(eventForTimelineUpdateId100);
    String updatedSessionId100 = sessionManager.getSessionForMediaPeriodId(timelineUpdate, eventForTimelineUpdateId100.mediaPeriodId);
    String updatedSessionId300 = sessionManager.getSessionForMediaPeriodId(timelineUpdate, eventForTimelineUpdateId300.mediaPeriodId);
    verify(mockListener).onSessionCreated(eventForInitialTimelineId100, sessionId100);
    verify(mockListener).onSessionActive(eventForInitialTimelineId100, sessionId100);
    verify(mockListener).onSessionCreated(eventForInitialTimelineId200, sessionId200);
    verify(mockListener).onSessionCreated(eventForInitialTimelineId300, sessionId300);
    verify(mockListener).onSessionFinished(eventForTimelineUpdateId100, sessionId200, /* automaticTransitionToNextPlayback= */
    false);
    verifyNoMoreInteractions(mockListener);
    assertThat(updatedSessionId100).isEqualTo(sessionId100);
    assertThat(updatedSessionId300).isEqualTo(sessionId300);
}
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 79 with TimelineWindowDefinition

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

the class DefaultPlaybackSessionManagerTest method positionDiscontinuity_withinWindow_doesNotFinishSession.

@Test
public void positionDiscontinuity_withinWindow_doesNotFinishSession() {
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    2, /* id= */
    100));
    EventTime eventTime1 = createEventTime(timeline, /* windowIndex= */
    0, new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0));
    EventTime eventTime2 = createEventTime(timeline, /* windowIndex= */
    0, new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    1), /* windowSequenceNumber= */
    0));
    sessionManager.updateSessionsWithTimelineChange(eventTime1);
    sessionManager.updateSessions(eventTime2);
    sessionManager.updateSessionsWithDiscontinuity(eventTime2, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
    verify(mockListener).onSessionCreated(eq(eventTime1), anyString());
    verify(mockListener).onSessionActive(eq(eventTime1), anyString());
    verifyNoMoreInteractions(mockListener);
}
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) Test(org.junit.Test)

Example 80 with TimelineWindowDefinition

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

the class DefaultPlaybackSessionManagerTest method updateSessions_withOtherMediaPeriodId_ofSameWindow_doesNotCreateNewSession.

@Test
public void updateSessions_withOtherMediaPeriodId_ofSameWindow_doesNotCreateNewSession() {
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    2, /* id= */
    0));
    MediaPeriodId mediaPeriodId1 = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0);
    MediaPeriodId mediaPeriodId2 = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    1), /* windowSequenceNumber= */
    0);
    EventTime eventTime1 = createEventTime(timeline, /* windowIndex= */
    0, mediaPeriodId1);
    EventTime eventTime2 = createEventTime(timeline, /* windowIndex= */
    0, mediaPeriodId2);
    sessionManager.updateSessions(eventTime1);
    sessionManager.updateSessions(eventTime2);
    ArgumentCaptor<String> sessionId = ArgumentCaptor.forClass(String.class);
    verify(mockListener).onSessionCreated(eq(eventTime1), sessionId.capture());
    verify(mockListener).onSessionActive(eventTime1, sessionId.getValue());
    verifyNoMoreInteractions(mockListener);
    assertThat(sessionManager.getSessionForMediaPeriodId(timeline, mediaPeriodId1)).isEqualTo(sessionId.getValue());
    assertThat(sessionManager.getSessionForMediaPeriodId(timeline, mediaPeriodId2)).isEqualTo(sessionId.getValue());
}
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)

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