use of androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime in project media by androidx.
the class ExoPlayerTest method repeatModeChanges.
@Test
public void repeatModeChanges() throws Exception {
Timeline timeline = new FakeTimeline(/* windowCount= */
3);
FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
AnalyticsListener mockAnalyticsListener = mock(AnalyticsListener.class);
player.addAnalyticsListener(mockAnalyticsListener);
player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
player.prepare();
runUntilTimelineChanged(player);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
1);
player.setRepeatMode(Player.REPEAT_MODE_ONE);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
1);
player.setRepeatMode(Player.REPEAT_MODE_OFF);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
2);
player.setRepeatMode(Player.REPEAT_MODE_ONE);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
2);
player.setRepeatMode(Player.REPEAT_MODE_ALL);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
0);
player.setRepeatMode(Player.REPEAT_MODE_ONE);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
0);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
0);
player.setRepeatMode(Player.REPEAT_MODE_OFF);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
1);
playUntilStartOfMediaItem(player, /* mediaItemIndex= */
2);
player.play();
runUntilPlaybackState(player, Player.STATE_ENDED);
ArgumentCaptor<AnalyticsListener.EventTime> eventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
verify(mockAnalyticsListener, times(10)).onMediaItemTransition(eventTimes.capture(), any(), anyInt());
assertThat(eventTimes.getAllValues().stream().map(eventTime -> eventTime.currentWindowIndex).collect(Collectors.toList())).containsExactly(0, 1, 1, 2, 2, 0, 0, 0, 1, 2).inOrder();
assertThat(renderer.isEnded).isTrue();
}
use of androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime in project media by androidx.
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);
}
use of androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime in project media by androidx.
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);
}
use of androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime in project media by androidx.
the class DefaultPlaybackSessionManagerTest method updateSessions_withMediaPeriodId_createsNewSession.
@Test
public void updateSessions_withMediaPeriodId_createsNewSession() {
Timeline timeline = new FakeTimeline();
MediaPeriodId mediaPeriodId = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0);
EventTime eventTime = createEventTime(timeline, /* windowIndex= */
0, mediaPeriodId);
sessionManager.updateSessions(eventTime);
ArgumentCaptor<String> sessionId = ArgumentCaptor.forClass(String.class);
verify(mockListener).onSessionCreated(eq(eventTime), sessionId.capture());
verify(mockListener).onSessionActive(eventTime, sessionId.getValue());
verifyNoMoreInteractions(mockListener);
assertThat(sessionManager.getSessionForMediaPeriodId(timeline, mediaPeriodId)).isEqualTo(sessionId.getValue());
}
use of androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime in project media by androidx.
the class DefaultAnalyticsCollector method onAudioAttributesChanged.
@Override
public final void onAudioAttributesChanged(AudioAttributes audioAttributes) {
EventTime eventTime = generateReadingMediaPeriodEventTime();
sendEvent(eventTime, AnalyticsListener.EVENT_AUDIO_ATTRIBUTES_CHANGED, listener -> listener.onAudioAttributesChanged(eventTime, audioAttributes));
}
Aggregations