Search in sources :

Example 1 with FakeRenderer

use of androidx.media3.test.utils.FakeRenderer in project media by androidx.

the class ExoPlayerTest method renderersLifecycle_renderersThatAreNeverEnabled_areNotReset.

@Test
public void renderersLifecycle_renderersThatAreNeverEnabled_areNotReset() throws Exception {
    Timeline timeline = new FakeTimeline();
    final FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    final FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(videoRenderer, audioRenderer).build();
    Player.Listener mockPlayerListener = mock(Player.Listener.class);
    player.addListener(mockPlayerListener);
    player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.AUDIO_FORMAT));
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    assertThat(audioRenderer.enabledCount).isEqualTo(1);
    assertThat(audioRenderer.resetCount).isEqualTo(1);
    assertThat(videoRenderer.enabledCount).isEqualTo(0);
    assertThat(videoRenderer.resetCount).isEqualTo(0);
}
Also used : FakeRenderer(androidx.media3.test.utils.FakeRenderer) Listener(androidx.media3.common.Player.Listener) Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) Player(androidx.media3.common.Player) 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 FakeRenderer

use of androidx.media3.test.utils.FakeRenderer in project media by androidx.

the class ExoPlayerTest method playSinglePeriodTimeline.

/**
 * Tests playback of a source that exposes a single period.
 */
@Test
public void playSinglePeriodTimeline() throws Exception {
    Timeline timeline = new FakeTimeline();
    FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
    Player.Listener mockListener = mock(Player.Listener.class);
    player.addListener(mockListener);
    player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    InOrder inOrder = Mockito.inOrder(mockListener);
    inOrder.verify(mockListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockListener).onTimelineChanged(argThat(noUid(timeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
    inOrder.verify(mockListener).onTracksChanged(eq(new TrackGroupArray(new TrackGroup(ExoPlayerTestRunner.VIDEO_FORMAT))), any());
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(anyInt());
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
    assertThat(renderer.getFormatsRead()).containsExactly(ExoPlayerTestRunner.VIDEO_FORMAT);
    assertThat(renderer.sampleBufferReadCount).isEqualTo(1);
    assertThat(renderer.isEnded).isTrue();
}
Also used : FakeRenderer(androidx.media3.test.utils.FakeRenderer) Listener(androidx.media3.common.Player.Listener) Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) Player(androidx.media3.common.Player) InOrder(org.mockito.InOrder) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TrackGroup(androidx.media3.common.TrackGroup) TrackGroupArray(androidx.media3.common.TrackGroupArray) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 3 with FakeRenderer

use of androidx.media3.test.utils.FakeRenderer in project media by androidx.

the class ExoPlayerTest method setAndSwitchSurface.

@Test
public void setAndSwitchSurface() throws Exception {
    final List<Integer> rendererMessages = new ArrayList<>();
    Renderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO) {

        @Override
        public void handleMessage(@MessageType int messageType, @Nullable Object message) throws ExoPlaybackException {
            super.handleMessage(messageType, message);
            rendererMessages.add(messageType);
        }
    };
    ActionSchedule actionSchedule = addSurfaceSwitch(new ActionSchedule.Builder(TAG)).build();
    new ExoPlayerTestRunner.Builder(context).setRenderers(videoRenderer).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertThat(Collections.frequency(rendererMessages, Renderer.MSG_SET_VIDEO_OUTPUT)).isEqualTo(2);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeRenderer(androidx.media3.test.utils.FakeRenderer) ActionSchedule(androidx.media3.test.utils.ActionSchedule) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) ArrayList(java.util.ArrayList) FakeRenderer(androidx.media3.test.utils.FakeRenderer) FakeVideoRenderer(androidx.media3.test.utils.FakeVideoRenderer) FakeMediaClockRenderer(androidx.media3.test.utils.FakeMediaClockRenderer) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 4 with FakeRenderer

use of androidx.media3.test.utils.FakeRenderer in project media by androidx.

the class ExoPlayerTest method nextLoadPositionExceedingLoadControlMaxBuffer_whileCurrentLoadInProgress_doesNotThrowException.

@Test
public void nextLoadPositionExceedingLoadControlMaxBuffer_whileCurrentLoadInProgress_doesNotThrowException() throws Exception {
    long maxBufferUs = 2 * C.MICROS_PER_SECOND;
    LoadControl loadControlWithMaxBufferUs = new DefaultLoadControl() {

        @Override
        public boolean shouldContinueLoading(long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) {
            return bufferedDurationUs < maxBufferUs;
        }

        @Override
        public boolean shouldStartPlayback(long bufferedDurationUs, float playbackSpeed, boolean rebuffering, long targetLiveOffsetUs) {
            return true;
        }
    };
    MediaSource mediaSourceWithLoadInProgress = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
            return new FakeMediaPeriod(trackGroupArray, allocator, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, mediaSourceEventDispatcher) {

                @Override
                public long getBufferedPositionUs() {
                    // Pretend not to have buffered data yet.
                    return 0;
                }

                @Override
                public long getNextLoadPositionUs() {
                    // Set next load position beyond the maxBufferUs configured in the LoadControl.
                    return Long.MAX_VALUE;
                }

                @Override
                public boolean isLoading() {
                    return true;
                }
            };
        }
    };
    FakeRenderer rendererWaitingForData = new FakeRenderer(C.TRACK_TYPE_VIDEO) {

        @Override
        public boolean isReady() {
            return false;
        }
    };
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(rendererWaitingForData).setLoadControl(loadControlWithMaxBufferUs).build();
    player.setMediaSource(mediaSourceWithLoadInProgress);
    player.prepare();
    // Wait until the MediaSource is prepared, i.e. returned its timeline, and at least one
    // iteration of doSomeWork after this was run.
    TestPlayerRunHelper.runUntilTimelineChanged(player);
    runUntilPendingCommandsAreFullyHandled(player);
    assertThat(player.getPlayerError()).isNull();
}
Also used : TransferListener(androidx.media3.datasource.TransferListener) Allocator(androidx.media3.exoplayer.upstream.Allocator) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) TrackGroupArray(androidx.media3.common.TrackGroupArray) FakeRenderer(androidx.media3.test.utils.FakeRenderer) FakeMediaPeriod(androidx.media3.test.utils.FakeMediaPeriod) CompositeMediaSource(androidx.media3.exoplayer.source.CompositeMediaSource) ClippingMediaSource(androidx.media3.exoplayer.source.ClippingMediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) MaskingMediaSource(androidx.media3.exoplayer.source.MaskingMediaSource) ServerSideAdInsertionMediaSource(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(androidx.media3.test.utils.FakeAdaptiveMediaSource) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) MediaSource(androidx.media3.exoplayer.source.MediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 5 with FakeRenderer

use of androidx.media3.test.utils.FakeRenderer 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)

Aggregations

FakeRenderer (androidx.media3.test.utils.FakeRenderer)27 Test (org.junit.Test)27 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)25 FakeTimeline (androidx.media3.test.utils.FakeTimeline)25 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)24 Timeline (androidx.media3.common.Timeline)21 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)17 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)17 Player (androidx.media3.common.Player)15 Listener (androidx.media3.common.Player.Listener)12 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)12 MediaSource (androidx.media3.exoplayer.source.MediaSource)12 ActionSchedule (androidx.media3.test.utils.ActionSchedule)11 InOrder (org.mockito.InOrder)11 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)10 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)10 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)9 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)9 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)9 ServerSideAdInsertionMediaSource (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource)9