Search in sources :

Example 21 with Listener

use of androidx.media3.common.Player.Listener in project media by androidx.

the class DefaultAnalyticsCollectorTest method drmEvents_periodsWithSameDrmData_keysReusedButLoadEventReportedTwice.

@Test
public void drmEvents_periodsWithSameDrmData_keysReusedButLoadEventReportedTwice() throws Exception {
    BlockingDrmCallback mediaDrmCallback = BlockingDrmCallback.returnsEmpty();
    DrmSessionManager blockingDrmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm.Builder().setEnforceValidKeyResponses(false).build()).setMultiSession(true).build(mediaDrmCallback);
    MediaSource mediaSource = new ConcatenatingMediaSource(new FakeMediaSource(SINGLE_PERIOD_TIMELINE, blockingDrmSessionManager, VIDEO_FORMAT_DRM_1), new FakeMediaSource(SINGLE_PERIOD_TIMELINE, blockingDrmSessionManager, VIDEO_FORMAT_DRM_1));
    TestAnalyticsListener listener = runAnalyticsTest(mediaSource, // already preacquired by the time the key load completes).
    new ActionSchedule.Builder(TAG).waitForIsLoading(false).waitForIsLoading(true).waitForIsLoading(false).executeRunnable(mediaDrmCallback.keyCondition::open).build());
    populateEventIds(listener.lastReportedTimeline);
    assertThat(listener.getEvents(EVENT_DRM_SESSION_MANAGER_ERROR)).isEmpty();
    assertThat(listener.getEvents(EVENT_DRM_SESSION_ACQUIRED)).containsExactly(period0, period1).inOrder();
    // This includes both period0 and period1 because period1's DrmSession was preacquired before
    // the key load completed. There's only one key load (a second would block forever). We can't
    // assume the order these events will arrive in because it depends on the iteration order of a
    // HashSet of EventDispatchers inside DefaultDrmSession.
    assertThat(listener.getEvents(EVENT_DRM_KEYS_LOADED)).containsExactly(period0, period1);
    // The period1 release event is lost because it's posted to "ExoPlayerTest thread" after that
    // thread has been quit during clean-up.
    assertThat(listener.getEvents(EVENT_DRM_SESSION_RELEASED)).containsExactly(period0);
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) MediaSource(androidx.media3.exoplayer.source.MediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) DefaultDrmSessionManager(androidx.media3.exoplayer.drm.DefaultDrmSessionManager) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) DefaultDrmSessionManager(androidx.media3.exoplayer.drm.DefaultDrmSessionManager) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) Test(org.junit.Test)

Example 22 with Listener

use of androidx.media3.common.Player.Listener in project media by androidx.

the class DefaultAnalyticsCollectorTest method onPlayerError_thrownDuringRenderAtPeriodTransition_isReportedForNewPeriod.

@Test
public void onPlayerError_thrownDuringRenderAtPeriodTransition_isReportedForNewPeriod() throws Exception {
    FakeMediaSource source0 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT);
    FakeMediaSource source1 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
    RenderersFactory renderersFactory = (eventHandler, videoListener, audioListener, textOutput, metadataOutput) -> new Renderer[] { new FakeRenderer(C.TRACK_TYPE_VIDEO), new FakeRenderer(C.TRACK_TYPE_AUDIO) {

        @Override
        public void render(long positionUs, long realtimeUs) throws ExoPlaybackException {
            // transition.
            throw createRendererException(new IllegalStateException(), ExoPlayerTestRunner.AUDIO_FORMAT, PlaybackException.ERROR_CODE_UNSPECIFIED);
        }
    } };
    TestAnalyticsListener listener = runAnalyticsTest(new ConcatenatingMediaSource(source0, source1), /* actionSchedule= */
    null, renderersFactory);
    populateEventIds(listener.lastReportedTimeline);
    assertThat(listener.getEvents(EVENT_PLAYER_ERROR)).containsExactly(period1);
}
Also used : ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) EVENT_PLAYER_RELEASED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_PLAYER_RELEASED) FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) ExoMediaDrm(androidx.media3.exoplayer.drm.ExoMediaDrm) Looper(android.os.Looper) DecoderCounters(androidx.media3.exoplayer.DecoderCounters) EVENT_DRM_SESSION_ACQUIRED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DRM_SESSION_ACQUIRED) EVENT_AUDIO_INPUT_FORMAT_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_AUDIO_INPUT_FORMAT_CHANGED) EVENT_AUDIO_DECODER_INITIALIZED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_AUDIO_DECODER_INITIALIZED) Surface(android.view.Surface) DrmSession(androidx.media3.exoplayer.drm.DrmSession) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) MediaLoadData(androidx.media3.exoplayer.source.MediaLoadData) EVENT_PLAY_WHEN_READY_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_PLAY_WHEN_READY_CHANGED) TestPlayerRunHelper(androidx.media3.test.utils.robolectric.TestPlayerRunHelper) EVENT_DRM_KEYS_LOADED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DRM_KEYS_LOADED) EVENT_IS_PLAYING_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_IS_PLAYING_CHANGED) EVENT_PLAYBACK_STATE_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_PLAYBACK_STATE_CHANGED) Nullable(androidx.annotation.Nullable) ArgumentMatchers.anyFloat(org.mockito.ArgumentMatchers.anyFloat) Timeline(androidx.media3.common.Timeline) FakeRenderer(androidx.media3.test.utils.FakeRenderer) FakeClock(androidx.media3.test.utils.FakeClock) Mockito.mock(org.mockito.Mockito.mock) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) AdPlaybackState(androidx.media3.common.AdPlaybackState) RunWith(org.junit.runner.RunWith) EVENT_TIMELINE_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_TIMELINE_CHANGED) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) FakeAudioRenderer(androidx.media3.test.utils.FakeAudioRenderer) EVENT_MEDIA_ITEM_TRANSITION(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_MEDIA_ITEM_TRANSITION) EVENT_AUDIO_DISABLED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_AUDIO_DISABLED) RenderersFactory(androidx.media3.exoplayer.RenderersFactory) EVENT_DOWNSTREAM_FORMAT_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DOWNSTREAM_FORMAT_CHANGED) Player(androidx.media3.common.Player) ShadowLooper(org.robolectric.shadows.ShadowLooper) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) EVENT_IS_LOADING_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_IS_LOADING_CHANGED) EVENT_LOAD_COMPLETED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_LOAD_COMPLETED) IOException(java.io.IOException) Test(org.junit.Test) ConditionVariable(androidx.media3.common.util.ConditionVariable) FakeVideoRenderer(androidx.media3.test.utils.FakeVideoRenderer) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) DrmInitData(androidx.media3.common.DrmInitData) ExoPlaybackException(androidx.media3.exoplayer.ExoPlaybackException) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) EVENT_LOAD_ERROR(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_LOAD_ERROR) EVENT_DROPPED_VIDEO_FRAMES(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DROPPED_VIDEO_FRAMES) EVENT_PLAYER_ERROR(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_PLAYER_ERROR) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) EVENT_TRACKS_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_TRACKS_CHANGED) ApplicationProvider(androidx.test.core.app.ApplicationProvider) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) END_OF_STREAM_ITEM(androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) Renderer(androidx.media3.exoplayer.Renderer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestUtil(androidx.media3.test.utils.TestUtil) EVENT_DRM_SESSION_MANAGER_ERROR(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DRM_SESSION_MANAGER_ERROR) EVENT_VIDEO_ENABLED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_ENABLED) EVENT_DRM_SESSION_RELEASED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DRM_SESSION_RELEASED) MediaItem(androidx.media3.common.MediaItem) EVENT_VIDEO_FRAME_PROCESSING_OFFSET(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_FRAME_PROCESSING_OFFSET) DefaultDrmSessionManager(androidx.media3.exoplayer.drm.DefaultDrmSessionManager) Method(java.lang.reflect.Method) MediaDrmCallback(androidx.media3.exoplayer.drm.MediaDrmCallback) EVENT_POSITION_DISCONTINUITY(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_POSITION_DISCONTINUITY) VideoSize(androidx.media3.common.VideoSize) PlaybackException(androidx.media3.common.PlaybackException) UUID(java.util.UUID) Util(androidx.media3.common.util.Util) MediaDrmCallbackException(androidx.media3.exoplayer.drm.MediaDrmCallbackException) Format(androidx.media3.common.Format) EVENT_PLAYBACK_PARAMETERS_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_PLAYBACK_PARAMETERS_CHANGED) SparseArray(android.util.SparseArray) PlaybackParameters(androidx.media3.common.PlaybackParameters) List(java.util.List) Mockito.inOrder(org.mockito.Mockito.inOrder) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) EVENT_LOAD_STARTED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_LOAD_STARTED) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Metadata(androidx.media3.common.Metadata) TracksInfo(androidx.media3.common.TracksInfo) EVENT_VIDEO_DISABLED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_DISABLED) FakeTimeline(androidx.media3.test.utils.FakeTimeline) AtomicReference(java.util.concurrent.atomic.AtomicReference) ActionSchedule(androidx.media3.test.utils.ActionSchedule) EVENT_AUDIO_POSITION_ADVANCING(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_AUDIO_POSITION_ADVANCING) EVENT_VIDEO_INPUT_FORMAT_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_INPUT_FORMAT_CHANGED) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) EVENT_VIDEO_SIZE_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_SIZE_CHANGED) Window(androidx.media3.common.Timeline.Window) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) EVENT_VIDEO_DECODER_INITIALIZED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_DECODER_INITIALIZED) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) SurfaceTexture(android.graphics.SurfaceTexture) MediaSource(androidx.media3.exoplayer.source.MediaSource) InOrder(org.mockito.InOrder) Iterator(java.util.Iterator) MimeTypes(androidx.media3.common.MimeTypes) Clock(androidx.media3.common.util.Clock) Truth.assertThat(com.google.common.truth.Truth.assertThat) EVENT_AUDIO_ENABLED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_AUDIO_ENABLED) Mockito.verify(org.mockito.Mockito.verify) C(androidx.media3.common.C) EVENT_RENDERED_FIRST_FRAME(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_RENDERED_FIRST_FRAME) FakeSampleStreamItem.oneByteSample(androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem.oneByteSample) RobolectricUtil(androidx.media3.test.utils.robolectric.RobolectricUtil) FakeRenderer(androidx.media3.test.utils.FakeRenderer) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) FakeRenderer(androidx.media3.test.utils.FakeRenderer) FakeAudioRenderer(androidx.media3.test.utils.FakeAudioRenderer) FakeVideoRenderer(androidx.media3.test.utils.FakeVideoRenderer) Renderer(androidx.media3.exoplayer.Renderer) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) RenderersFactory(androidx.media3.exoplayer.RenderersFactory) Test(org.junit.Test)

Example 23 with Listener

use of androidx.media3.common.Player.Listener in project media by androidx.

the class DefaultAnalyticsCollectorTest method prepareNewSource.

@Test
public void prepareNewSource() throws Exception {
    MediaSource mediaSource1 = new FakeMediaSource(SINGLE_PERIOD_TIMELINE, ExoPlayerTestRunner.VIDEO_FORMAT);
    MediaSource mediaSource2 = new FakeMediaSource(SINGLE_PERIOD_TIMELINE, ExoPlayerTestRunner.VIDEO_FORMAT);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).setMediaSources(/* resetPosition= */
    false, mediaSource2).waitForTimelineChanged().waitForIsLoading(true).play().build();
    TestAnalyticsListener listener = runAnalyticsTest(mediaSource1, actionSchedule);
    // Populate all event ids with last timeline (after second prepare).
    populateEventIds(listener.lastReportedTimeline);
    // Populate event id of period 0, sequence 0 with timeline of initial preparation.
    period0Seq0 = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(listener.reportedTimelines.get(1).getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0));
    assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
    WINDOW_0, /* BUFFERING */
    WINDOW_0, /* setPlayWhenReady=false */
    period0Seq0, /* READY */
    WINDOW_0, /* BUFFERING */
    period0Seq1, /* setPlayWhenReady=true */
    period0Seq1, /* READY */
    period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* PLAYLIST_CHANGE */
    period0Seq0, /* SOURCE_UPDATE */
    WINDOW_0, /* PLAYLIST_CHANGE */
    period0Seq1);
    assertThat(listener.getEvents(EVENT_POSITION_DISCONTINUITY)).containsExactly(WINDOW_0);
    assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(period0Seq0, period0Seq0, period0Seq1, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(period0Seq0, /* prepared */
    WINDOW_0, /* setMediaSources */
    period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* manifest */
    period0Seq0, /* media */
    WINDOW_0, /* manifest */
    period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* manifest */
    period0Seq0, /* media */
    WINDOW_0, /* manifest */
    period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(period0Seq0, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(period0Seq0, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(period0Seq0, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(period0Seq0, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(period0Seq0);
    assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(period0Seq0, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(period0Seq0, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(period0Seq0, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(period0Seq0);
    assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(period0Seq1);
    assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(period0Seq0, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(period0Seq0, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(period0Seq1);
    listener.assertNoMoreEvents();
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) MediaSource(androidx.media3.exoplayer.source.MediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 24 with Listener

use of androidx.media3.common.Player.Listener in project media by androidx.

the class DefaultAnalyticsCollectorTest method seekAfterMidroll.

@Test
public void seekAfterMidroll() throws Exception {
    long windowOffsetInFirstPeriodUs = TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
    Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, 10 * C.MICROS_PER_SECOND, FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    1, /* adGroupTimesUs...= */
    windowOffsetInFirstPeriodUs + 5 * C.MICROS_PER_SECOND)));
    FakeMediaSource fakeMediaSource = new FakeMediaSource(adTimeline, DrmSessionManager.DRM_UNSUPPORTED, (unusedFormat, mediaPeriodId) -> {
        if (mediaPeriodId.isAd()) {
            return ImmutableList.of(oneByteSample(/* timeUs= */
            0, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM);
        } else {
            // Provide a sample before the midroll and another after the seek point below (6s).
            return ImmutableList.of(oneByteSample(windowOffsetInFirstPeriodUs + C.MICROS_PER_SECOND, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(windowOffsetInFirstPeriodUs + 7 * C.MICROS_PER_SECOND, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM);
        }
    }, ExoPlayerTestRunner.VIDEO_FORMAT);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForIsLoading(true).waitForIsLoading(false).seek(6 * C.MICROS_PER_SECOND).waitForIsLoading(true).play().waitForPlaybackState(Player.STATE_ENDED).build();
    TestAnalyticsListener listener = runAnalyticsTest(fakeMediaSource, actionSchedule);
    Object periodUid = listener.lastReportedTimeline.getUidOfPeriod(/* periodIndex= */
    0);
    EventWindowAndPeriodId midrollAd = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    0));
    EventWindowAndPeriodId contentBeforeMidroll = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    0));
    EventWindowAndPeriodId contentAfterMidroll = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    C.INDEX_UNSET));
    assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
    WINDOW_0, /* setPlayWhenReady=false */
    WINDOW_0, /* BUFFERING */
    contentBeforeMidroll, /* READY */
    contentAfterMidroll, /* BUFFERING */
    midrollAd, /* setPlayWhenReady=true */
    midrollAd, /* READY */
    contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* PLAYLIST_CHANGED */
    contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_POSITION_DISCONTINUITY)).containsExactly(contentAfterMidroll, /* seek */
    midrollAd, /* seek adjustment */
    contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_SEEK_STARTED)).containsExactly(contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_SEEK_PROCESSED)).containsExactly(contentAfterMidroll);
    assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(contentBeforeMidroll, contentBeforeMidroll, midrollAd, midrollAd).inOrder();
    assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll);
    assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* content manifest */
    contentBeforeMidroll, midrollAd, contentAfterMidroll, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* content manifest */
    contentBeforeMidroll, midrollAd, contentAfterMidroll, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(contentBeforeMidroll, midrollAd).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(contentBeforeMidroll, midrollAd).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(contentAfterMidroll);
    assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(contentAfterMidroll);
    listener.assertNoMoreEvents();
}
Also used : Timeline(androidx.media3.common.Timeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 25 with Listener

use of androidx.media3.common.Player.Listener in project media by androidx.

the class DefaultAnalyticsCollectorTest method runAnalyticsTest.

private static TestAnalyticsListener runAnalyticsTest(MediaSource mediaSource, @Nullable ActionSchedule actionSchedule, RenderersFactory renderersFactory) throws Exception {
    Surface surface = new Surface(new SurfaceTexture(/* texName= */
    0));
    TestAnalyticsListener listener = new TestAnalyticsListener();
    try {
        new ExoPlayerTestRunner.Builder(ApplicationProvider.getApplicationContext()).setMediaSources(mediaSource).setRenderersFactory(renderersFactory).setVideoSurface(surface).setAnalyticsListener(listener).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    } catch (ExoPlaybackException e) {
    // Ignore ExoPlaybackException as these may be expected.
    } finally {
        surface.release();
    }
    return listener;
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) ExoPlaybackException(androidx.media3.exoplayer.ExoPlaybackException) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Surface(android.view.Surface)

Aggregations

Test (org.junit.Test)216 Player (androidx.media3.common.Player)173 CountDownLatch (java.util.concurrent.CountDownLatch)143 AtomicReference (java.util.concurrent.atomic.AtomicReference)108 LargeTest (androidx.test.filters.LargeTest)102 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)102 MediaItem (androidx.media3.common.MediaItem)70 Timeline (androidx.media3.common.Timeline)70 EventTime (androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)68 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)58 PositionInfo (androidx.media3.common.Player.PositionInfo)56 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)54 Bundle (android.os.Bundle)50 Listener (androidx.media3.common.Player.Listener)45 ArrayList (java.util.ArrayList)45 Nullable (androidx.annotation.Nullable)42 RemoteMockPlayer (androidx.media3.session.RemoteMediaSession.RemoteMockPlayer)40 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)36 AtomicLong (java.util.concurrent.atomic.AtomicLong)36 MediaSource (androidx.media3.exoplayer.source.MediaSource)35