Search in sources :

Example 26 with Player

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

the class ExoPlayerTest method seekToPrevious_withPreviousWindowAndCloseToStart_seeksToPreviousWindow.

@Test
public void seekToPrevious_withPreviousWindowAndCloseToStart_seeksToPreviousWindow() {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()));
    player.seekTo(/* mediaItemIndex= */
    1, C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS);
    player.seekToPrevious();
    assertThat(player.getCurrentMediaItemIndex()).isEqualTo(0);
    assertThat(player.getCurrentPosition()).isEqualTo(0);
    player.release();
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 27 with Player

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

the class ExoPlayerTest method clearMediaItems_correctMaskingPosition.

@Test
public void clearMediaItems_correctMaskingPosition() throws Exception {
    final int[] mediaItemIndex = { C.INDEX_UNSET, C.INDEX_UNSET };
    final long[] positionMs = { C.INDEX_UNSET, C.INDEX_UNSET };
    final long[] bufferedPositions = { C.INDEX_UNSET, C.INDEX_UNSET };
    final long[] totalBufferedDuration = { C.INDEX_UNSET, C.INDEX_UNSET };
    runPositionMaskingCapturingActionSchedule(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            player.clearMediaItems();
        }
    }, /* pauseMediaItemIndex= */
    0, mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */
    4000));
    assertThat(mediaItemIndex[0]).isEqualTo(0);
    assertThat(positionMs[0]).isEqualTo(0);
    assertThat(bufferedPositions[0]).isEqualTo(0);
    assertThat(totalBufferedDuration[0]).isEqualTo(0);
    assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]);
    assertThat(positionMs[1]).isEqualTo(positionMs[0]);
    assertThat(bufferedPositions[1]).isEqualTo(bufferedPositions[0]);
    assertThat(totalBufferedDuration[1]).isEqualTo(totalBufferedDuration[0]);
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) Test(org.junit.Test)

Example 28 with Player

use of androidx.media3.common.Player 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 29 with Player

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

the class ExoPlayerTest method addMediaSources_whenEmptyInitialSeek_correctPeriodMasking.

@Test
public void addMediaSources_whenEmptyInitialSeek_correctPeriodMasking() throws Exception {
    final long[] positions = new long[2];
    Arrays.fill(positions, C.TIME_UNSET);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPositionDiscontinuity().waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            player.addMediaSource(/* index= */
            0, new FakeMediaSource());
            positions[0] = player.getCurrentPosition();
            positions[1] = player.getBufferedPosition();
        }
    }).prepare().build();
    new ExoPlayerTestRunner.Builder(context).skipSettingMediaSources().initialSeek(/* mediaItemIndex= */
    0, /* positionMs= */
    2000).setActionSchedule(actionSchedule).build().start(/* doPrepare= */
    false).blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertArrayEquals(new long[] { 2000, 2000 }, positions);
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Test(org.junit.Test)

Example 30 with Player

use of androidx.media3.common.Player 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)

Aggregations

Test (org.junit.Test)347 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)185 Player (androidx.media3.common.Player)183 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)174 Timeline (androidx.media3.common.Timeline)137 FakeTimeline (androidx.media3.test.utils.FakeTimeline)127 CountDownLatch (java.util.concurrent.CountDownLatch)108 PlayerRunnable (androidx.media3.test.utils.ActionSchedule.PlayerRunnable)107 LargeTest (androidx.test.filters.LargeTest)97 AtomicReference (java.util.concurrent.atomic.AtomicReference)95 ActionSchedule (androidx.media3.test.utils.ActionSchedule)91 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)89 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)89 Listener (androidx.media3.common.Player.Listener)85 MediaItem (androidx.media3.common.MediaItem)84 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)81 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)72 Nullable (androidx.annotation.Nullable)68 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)67 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)65