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();
}
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());
}
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);
}
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();
}
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);
}
Aggregations