Search in sources :

Example 96 with TimelineWindowDefinition

use of androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition in project media by androidx.

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 : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) EventTime(androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 97 with TimelineWindowDefinition

use of androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition in project media by androidx.

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 : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) EventTime(androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 98 with TimelineWindowDefinition

use of androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition in project media by androidx.

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 : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) AdPlaybackState(androidx.media3.common.AdPlaybackState) FakeTimeline(androidx.media3.test.utils.FakeTimeline) EventTime(androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 99 with TimelineWindowDefinition

use of androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition in project media by androidx.

the class DefaultPlaybackSessionManagerTest method updateSessions_ofSameWindow_withoutMediaPeriodId_afterAd_doesNotCreateNewSession.

@Test
public void updateSessions_ofSameWindow_withoutMediaPeriodId_afterAd_doesNotCreateNewSession() {
    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 adMediaPeriodId = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0), /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    0);
    MediaPeriodId contentMediaPeriodIdDuringAd = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    0);
    EventTime adEventTime = createEventTime(timeline, /* windowIndex= */
    0, adMediaPeriodId);
    EventTime contentEventTimeDuringAd = createEventTime(timeline, /* windowIndex= */
    0, contentMediaPeriodIdDuringAd, adMediaPeriodId);
    EventTime contentEventTimeWithoutMediaPeriodId = createEventTime(timeline, /* windowIndex= */
    0, /* mediaPeriodId= */
    null);
    sessionManager.updateSessions(adEventTime);
    sessionManager.updateSessions(contentEventTimeWithoutMediaPeriodId);
    verify(mockListener).onSessionCreated(eq(contentEventTimeDuringAd), anyString());
    ArgumentCaptor<String> adSessionId = ArgumentCaptor.forClass(String.class);
    verify(mockListener).onSessionCreated(eq(adEventTime), adSessionId.capture());
    verify(mockListener).onSessionActive(adEventTime, adSessionId.getValue());
    verifyNoMoreInteractions(mockListener);
    assertThat(sessionManager.getSessionForMediaPeriodId(timeline, adMediaPeriodId)).isEqualTo(adSessionId.getValue());
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) EventTime(androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 100 with TimelineWindowDefinition

use of androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition in project media by androidx.

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 : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) InOrder(org.mockito.InOrder) FakeTimeline(androidx.media3.test.utils.FakeTimeline) EventTime(androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)103 FakeTimeline (androidx.media3.test.utils.FakeTimeline)101 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)101 Timeline (androidx.media3.common.Timeline)80 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)79 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)69 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)61 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)61 ActionSchedule (androidx.media3.test.utils.ActionSchedule)35 AdPlaybackState (androidx.media3.common.AdPlaybackState)30 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)28 Listener (androidx.media3.common.Player.Listener)27 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)26 Player (androidx.media3.common.Player)25 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)22 PlayerRunnable (androidx.media3.test.utils.ActionSchedule.PlayerRunnable)20 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)18 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)16 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)16 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)16