Search in sources :

Example 1 with EventTime

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();
}
Also used : FakeRenderer(androidx.media3.test.utils.FakeRenderer) Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) AnalyticsListener(androidx.media3.exoplayer.analytics.AnalyticsListener) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 2 with EventTime

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);
}
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 3 with EventTime

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);
}
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with EventTime

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());
}
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 5 with EventTime

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));
}
Also used : EventTime(androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)

Aggregations

EventTime (androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)103 Test (org.junit.Test)41 Timeline (androidx.media3.common.Timeline)39 FakeTimeline (androidx.media3.test.utils.FakeTimeline)38 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)34 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)26 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)14 Nullable (androidx.annotation.Nullable)9 AdPlaybackState (androidx.media3.common.AdPlaybackState)6 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)6 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)5 PlaybackException (androidx.media3.common.PlaybackException)4 InOrder (org.mockito.InOrder)4 MediaItem (androidx.media3.common.MediaItem)3 PlaybackParameters (androidx.media3.common.PlaybackParameters)3 Player (androidx.media3.common.Player)3 ActionSchedule (androidx.media3.test.utils.ActionSchedule)3 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)3 IOException (java.io.IOException)3 Format (androidx.media3.common.Format)2