Search in sources :

Example 96 with MediaPeriodId

use of androidx.media3.exoplayer.source.MediaSource.MediaPeriodId 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 97 with MediaPeriodId

use of androidx.media3.exoplayer.source.MediaSource.MediaPeriodId in project media by androidx.

the class DefaultPlaybackSessionManagerTest method positionDiscontinuity_toSameWindow_withoutMediaPeriodId_doesNotFinishSession.

@Test
public void positionDiscontinuity_toSameWindow_withoutMediaPeriodId_doesNotFinishSession() {
    Timeline timeline = new FakeTimeline();
    EventTime eventTime1 = createEventTime(timeline, /* windowIndex= */
    0, new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0));
    EventTime eventTime2 = createEventTime(timeline, /* windowIndex= */
    0, /* mediaPeriodId= */
    null);
    sessionManager.updateSessionsWithTimelineChange(eventTime1);
    sessionManager.updateSessions(eventTime2);
    sessionManager.updateSessionsWithDiscontinuity(eventTime2, Player.DISCONTINUITY_REASON_SEEK);
    verify(mockListener, never()).onSessionFinished(any(), anyString(), anyBoolean());
}
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) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 98 with MediaPeriodId

use of androidx.media3.exoplayer.source.MediaSource.MediaPeriodId in project media by androidx.

the class DefaultPlaybackSessionManagerTest method positionDiscontinuity_toNewWindow_withSeekTransitionReason_finishesSession.

@Test
public void positionDiscontinuity_toNewWindow_withSeekTransitionReason_finishesSession() {
    Timeline timeline = new FakeTimeline(/* windowCount= */
    2);
    EventTime eventTime1 = createEventTime(timeline, /* windowIndex= */
    0, new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0));
    EventTime eventTime2 = createEventTime(timeline, /* windowIndex= */
    1, new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    1), /* windowSequenceNumber= */
    1));
    sessionManager.updateSessionsWithTimelineChange(eventTime1);
    sessionManager.updateSessions(eventTime2);
    String sessionId1 = sessionManager.getSessionForMediaPeriodId(timeline, eventTime1.mediaPeriodId);
    String sessionId2 = sessionManager.getSessionForMediaPeriodId(timeline, eventTime2.mediaPeriodId);
    sessionManager.updateSessionsWithDiscontinuity(eventTime2, Player.DISCONTINUITY_REASON_SEEK);
    verify(mockListener).onSessionCreated(eventTime1, sessionId1);
    verify(mockListener).onSessionActive(eventTime1, sessionId1);
    verify(mockListener).onSessionCreated(eq(eventTime2), anyString());
    verify(mockListener).onSessionFinished(eventTime2, sessionId1, /* automaticTransitionToNextPlayback= */
    false);
    verify(mockListener).onSessionActive(eventTime2, sessionId2);
    verifyNoMoreInteractions(mockListener);
}
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) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 99 with MediaPeriodId

use of androidx.media3.exoplayer.source.MediaSource.MediaPeriodId in project media by androidx.

the class DefaultPlaybackSessionManagerTest method belongsToSession_withOtherWindowIndex_returnsFalse.

@Test
public void belongsToSession_withOtherWindowIndex_returnsFalse() {
    Timeline timeline = new FakeTimeline(/* windowCount= */
    2);
    EventTime eventTime = createEventTime(timeline, /* windowIndex= */
    0, /* mediaPeriodId= */
    null);
    EventTime eventTimeOtherWindow = createEventTime(timeline, /* windowIndex= */
    1, /* mediaPeriodId= */
    null);
    MediaPeriodId mediaPeriodId = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    1), /* windowSequenceNumber= */
    1);
    EventTime eventTimeWithOtherMediaPeriodId = createEventTime(timeline, /* windowIndex= */
    1, mediaPeriodId);
    sessionManager.updateSessions(eventTime);
    ArgumentCaptor<String> sessionId = ArgumentCaptor.forClass(String.class);
    verify(mockListener).onSessionCreated(eq(eventTime), sessionId.capture());
    assertThat(sessionManager.belongsToSession(eventTimeOtherWindow, sessionId.getValue())).isFalse();
    assertThat(sessionManager.belongsToSession(eventTimeWithOtherMediaPeriodId, sessionId.getValue())).isFalse();
}
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) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 100 with MediaPeriodId

use of androidx.media3.exoplayer.source.MediaSource.MediaPeriodId in project media by androidx.

the class DefaultPlaybackSessionManagerTest method positionDiscontinuity_toNewWindow_withPeriodTransitionReason_finishesSession.

@Test
public void positionDiscontinuity_toNewWindow_withPeriodTransitionReason_finishesSession() {
    Timeline timeline = new FakeTimeline(/* windowCount= */
    2);
    EventTime eventTime1 = createEventTime(timeline, /* windowIndex= */
    0, new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0));
    EventTime eventTime2 = createEventTime(timeline, /* windowIndex= */
    1, new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    1), /* windowSequenceNumber= */
    1));
    sessionManager.updateSessionsWithTimelineChange(eventTime1);
    sessionManager.updateSessions(eventTime2);
    String sessionId1 = sessionManager.getSessionForMediaPeriodId(timeline, eventTime1.mediaPeriodId);
    String sessionId2 = sessionManager.getSessionForMediaPeriodId(timeline, eventTime2.mediaPeriodId);
    sessionManager.updateSessionsWithDiscontinuity(eventTime2, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
    verify(mockListener).onSessionCreated(eventTime1, sessionId1);
    verify(mockListener).onSessionActive(eventTime1, sessionId1);
    verify(mockListener).onSessionCreated(eq(eventTime2), anyString());
    verify(mockListener).onSessionFinished(eventTime2, sessionId1, /* automaticTransitionToNextPlayback= */
    true);
    verify(mockListener).onSessionActive(eventTime2, sessionId2);
    verifyNoMoreInteractions(mockListener);
}
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) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)106 Test (org.junit.Test)85 FakeTimeline (androidx.media3.test.utils.FakeTimeline)75 Timeline (androidx.media3.common.Timeline)72 EventTime (androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)48 Nullable (androidx.annotation.Nullable)28 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)28 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)27 Allocator (androidx.media3.exoplayer.upstream.Allocator)22 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)19 AdPlaybackState (androidx.media3.common.AdPlaybackState)17 DrmSessionManager (androidx.media3.exoplayer.drm.DrmSessionManager)17 TrackGroupArray (androidx.media3.common.TrackGroupArray)16 TransferListener (androidx.media3.datasource.TransferListener)16 FakeMediaPeriod (androidx.media3.test.utils.FakeMediaPeriod)15 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)15 ActionSchedule (androidx.media3.test.utils.ActionSchedule)13 DrmSessionEventListener (androidx.media3.exoplayer.drm.DrmSessionEventListener)12 MediaPeriod (androidx.media3.exoplayer.source.MediaPeriod)11