use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class DefaultPlaybackSessionManagerTest method updateSessions_withAd_ofSameWindow_createsNewSession.
@Test
public void updateSessions_withAd_ofSameWindow_createsNewSession() {
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= */
0), /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
0);
EventTime eventTime1 = createEventTime(timeline, /* windowIndex= */
0, mediaPeriodId1);
EventTime eventTime2 = createEventTime(timeline, /* windowIndex= */
0, mediaPeriodId2);
sessionManager.updateSessions(eventTime1);
sessionManager.updateSessions(eventTime2);
ArgumentCaptor<String> contentSessionId = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> adSessionId = ArgumentCaptor.forClass(String.class);
verify(mockListener).onSessionCreated(eq(eventTime1), contentSessionId.capture());
verify(mockListener).onSessionActive(eventTime1, contentSessionId.getValue());
verify(mockListener).onSessionCreated(eq(eventTime2), adSessionId.capture());
verifyNoMoreInteractions(mockListener);
assertThat(contentSessionId).isNotEqualTo(adSessionId);
assertThat(sessionManager.getSessionForMediaPeriodId(timeline, mediaPeriodId1)).isEqualTo(contentSessionId.getValue());
assertThat(sessionManager.getSessionForMediaPeriodId(timeline, mediaPeriodId2)).isEqualTo(adSessionId.getValue());
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
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());
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
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());
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class DefaultPlaybackSessionManagerTest method timelineUpdate_withContent_doesNotFinishFuturePostrollAd.
@Test
public void timelineUpdate_withContent_doesNotFinishFuturePostrollAd() {
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=... */
C.TIME_END_OF_SOURCE).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1)));
EventTime adEventTime = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
0));
EventTime contentEventTime = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0, /* nextAdGroupIndex= */
0));
sessionManager.updateSessions(contentEventTime);
sessionManager.updateSessions(adEventTime);
sessionManager.updateSessionsWithTimelineChange(contentEventTime);
verify(mockListener, never()).onSessionFinished(any(), anyString(), anyBoolean());
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class DefaultPlaybackSessionManagerTest method positionDiscontinuity_fromAdToAd_finishesPastAds_andNotifiesAdPlaybackStated.
@Test
public void positionDiscontinuity_fromAdToAd_finishesPastAds_andNotifiesAdPlaybackStated() {
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 contentEventTime = createEventTime(adTimeline, /* windowIndex= */
0, new MediaPeriodId(adTimeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0, /* nextAdGroupIndex= */
1));
sessionManager.updateSessionsWithTimelineChange(contentEventTime);
sessionManager.updateSessions(adEventTime1);
sessionManager.updateSessions(adEventTime2);
String contentSessionId = sessionManager.getSessionForMediaPeriodId(adTimeline, contentEventTime.mediaPeriodId);
String adSessionId1 = sessionManager.getSessionForMediaPeriodId(adTimeline, adEventTime1.mediaPeriodId);
String adSessionId2 = sessionManager.getSessionForMediaPeriodId(adTimeline, adEventTime2.mediaPeriodId);
sessionManager.updateSessionsWithDiscontinuity(adEventTime1, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
sessionManager.updateSessionsWithDiscontinuity(adEventTime2, Player.DISCONTINUITY_REASON_SEEK);
verify(mockListener).onSessionCreated(eq(contentEventTime), anyString());
verify(mockListener).onSessionActive(eq(contentEventTime), anyString());
verify(mockListener).onSessionCreated(adEventTime1, adSessionId1);
verify(mockListener).onSessionCreated(adEventTime2, adSessionId2);
verify(mockListener).onAdPlaybackStarted(adEventTime1, contentSessionId, adSessionId1);
verify(mockListener).onSessionActive(adEventTime1, adSessionId1);
verify(mockListener).onSessionFinished(adEventTime2, adSessionId1, /* automaticTransitionToNextPlayback= */
false);
verify(mockListener).onAdPlaybackStarted(adEventTime2, contentSessionId, adSessionId2);
verify(mockListener).onSessionActive(adEventTime2, adSessionId2);
verifyNoMoreInteractions(mockListener);
}
Aggregations