Search in sources :

Example 11 with Player

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

the class DrmPlaybackTest method clearkeyPlayback.

@Test
public void clearkeyPlayback() throws Exception {
    MockWebServer mockWebServer = new MockWebServer();
    mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(CLEARKEY_RESPONSE));
    mockWebServer.start();
    MediaItem mediaItem = new MediaItem.Builder().setUri("asset:///media/drm/sample_fragmented_clearkey.mp4").setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.CLEARKEY_UUID).setLicenseUri(mockWebServer.url("license").toString()).build()).build();
    AtomicReference<ExoPlayer> player = new AtomicReference<>();
    ConditionVariable playbackComplete = new ConditionVariable();
    AtomicReference<PlaybackException> playbackException = new AtomicReference<>();
    getInstrumentation().runOnMainSync(() -> {
        player.set(new ExoPlayer.Builder(getInstrumentation().getContext()).build());
        player.get().addListener(new Player.Listener() {

            @Override
            public void onPlaybackStateChanged(@Player.State int playbackState) {
                if (playbackState == Player.STATE_ENDED) {
                    playbackComplete.open();
                }
            }

            @Override
            public void onPlayerError(PlaybackException error) {
                playbackException.set(error);
                playbackComplete.open();
            }
        });
        player.get().setMediaItem(mediaItem);
        player.get().prepare();
        player.get().play();
    });
    playbackComplete.block();
    getInstrumentation().runOnMainSync(() -> player.get().release());
    getInstrumentation().waitForIdleSync();
    assertThat(playbackException.get()).isNull();
}
Also used : PlaybackException(androidx.media3.common.PlaybackException) MockResponse(okhttp3.mockwebserver.MockResponse) Player(androidx.media3.common.Player) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) ConditionVariable(androidx.media3.common.util.ConditionVariable) MediaItem(androidx.media3.common.MediaItem) MockWebServer(okhttp3.mockwebserver.MockWebServer) Test(org.junit.Test)

Example 12 with Player

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

the class ExoPlayerTest method newServerSideInsertedAdAtPlaybackPosition_keepsRenderersEnabled.

@Test
public void newServerSideInsertedAdAtPlaybackPosition_keepsRenderersEnabled() throws Exception {
    // Injecting renderer to count number of renderer resets.
    AtomicReference<FakeVideoRenderer> videoRenderer = new AtomicReference<>();
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderersFactory((handler, videoListener, audioListener, textOutput, metadataOutput) -> {
        videoRenderer.set(new FakeVideoRenderer(handler, videoListener));
        return new Renderer[] { videoRenderer.get() };
    }).build();
    // Live stream timeline with unassigned next ad group.
    AdPlaybackState initialAdPlaybackState = new AdPlaybackState(/* adsId= */
    new Object(), /* adGroupTimesUs...= */
    C.TIME_END_OF_SOURCE).withIsServerSideInserted(/* adGroupIndex= */
    0, /* isServerSideInserted= */
    true).withAdCount(/* adGroupIndex= */
    0, /* adCount= */
    1).withAdDurationsUs(new long[][] { new long[] { 10 * C.MICROS_PER_SECOND } });
    // Updated timeline with ad group at 18 seconds.
    long firstSampleTimeUs = TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
    Timeline initialTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    true, /* durationUs= */
    C.TIME_UNSET, initialAdPlaybackState));
    AdPlaybackState updatedAdPlaybackState = initialAdPlaybackState.withAdGroupTimeUs(/* adGroupIndex= */
    0, /* adGroupTimeUs= */
    firstSampleTimeUs + 18 * C.MICROS_PER_SECOND);
    Timeline updatedTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    true, /* durationUs= */
    C.TIME_UNSET, updatedAdPlaybackState));
    // Add samples to allow player to load and start playing (but no EOS as this is a live stream).
    FakeMediaSource mediaSource = new FakeMediaSource(initialTimeline, DrmSessionManager.DRM_UNSUPPORTED, (format, mediaPeriodId) -> ImmutableList.of(oneByteSample(firstSampleTimeUs, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(firstSampleTimeUs + 40 * C.MICROS_PER_SECOND)), ExoPlayerTestRunner.VIDEO_FORMAT);
    // Set updated ad group once we reach 20 seconds, and then continue playing until 40 seconds.
    player.createMessage((message, payload) -> mediaSource.setNewSourceInfo(updatedTimeline)).setPosition(20_000).send();
    player.setMediaSource(mediaSource);
    player.prepare();
    playUntilPosition(player, /* mediaItemIndex= */
    0, /* positionMs= */
    40_000);
    player.release();
    // Assert that the renderer hasn't been reset despite the inserted ad group.
    assertThat(videoRenderer.get().positionResetCount).isEqualTo(1);
}
Also used : IllegalSeekPositionException(androidx.media3.common.IllegalSeekPositionException) COMMAND_ADJUST_DEVICE_VOLUME(androidx.media3.common.Player.COMMAND_ADJUST_DEVICE_VOLUME) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Uri(android.net.Uri) COMMAND_SEEK_TO_NEXT_MEDIA_ITEM(androidx.media3.common.Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM) COMMAND_GET_CURRENT_MEDIA_ITEM(androidx.media3.common.Player.COMMAND_GET_CURRENT_MEDIA_ITEM) Allocator(androidx.media3.exoplayer.upstream.Allocator) COMMAND_GET_MEDIA_ITEMS_METADATA(androidx.media3.common.Player.COMMAND_GET_MEDIA_ITEMS_METADATA) CompositeMediaSource(androidx.media3.exoplayer.source.CompositeMediaSource) DefaultTrackSelector(androidx.media3.exoplayer.trackselection.DefaultTrackSelector) COMMAND_SEEK_TO_MEDIA_ITEM(androidx.media3.common.Player.COMMAND_SEEK_TO_MEDIA_ITEM) COMMAND_GET_TIMELINE(androidx.media3.common.Player.COMMAND_GET_TIMELINE) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) Looper(android.os.Looper) COMMAND_SET_REPEAT_MODE(androidx.media3.common.Player.COMMAND_SET_REPEAT_MODE) ClippingMediaSource(androidx.media3.exoplayer.source.ClippingMediaSource) Surface(android.view.Surface) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Range(com.google.common.collect.Range) FakeSampleStream(androidx.media3.test.utils.FakeSampleStream) TextInformationFrame(androidx.media3.extractor.metadata.id3.TextInformationFrame) TestPlayerRunHelper(androidx.media3.test.utils.robolectric.TestPlayerRunHelper) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(androidx.annotation.Nullable) Allocation(androidx.media3.exoplayer.upstream.Allocation) ArgumentMatchers.anyFloat(org.mockito.ArgumentMatchers.anyFloat) Timeline(androidx.media3.common.Timeline) BinaryFrame(androidx.media3.extractor.metadata.id3.BinaryFrame) FakeRenderer(androidx.media3.test.utils.FakeRenderer) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeClock(androidx.media3.test.utils.FakeClock) Mockito.mock(org.mockito.Mockito.mock) AnalyticsListener(androidx.media3.exoplayer.analytics.AnalyticsListener) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Iterables(com.google.common.collect.Iterables) AdPlaybackState(androidx.media3.common.AdPlaybackState) Loader(androidx.media3.exoplayer.upstream.Loader) COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM(androidx.media3.common.Player.COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM) TestPlayerRunHelper.runUntilPositionDiscontinuity(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.runUntilPositionDiscontinuity) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) COMMAND_PLAY_PAUSE(androidx.media3.common.Player.COMMAND_PLAY_PAUSE) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ArrayList(java.util.ArrayList) FakeTrackSelection(androidx.media3.test.utils.FakeTrackSelection) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Assertions(androidx.media3.common.util.Assertions) DiscontinuityReason(androidx.media3.common.Player.DiscontinuityReason) COMMAND_SEEK_TO_DEFAULT_POSITION(androidx.media3.common.Player.COMMAND_SEEK_TO_DEFAULT_POSITION) Before(org.junit.Before) TransferListener(androidx.media3.datasource.TransferListener) MediaSourceEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener) Player(androidx.media3.common.Player) ShadowLooper(org.robolectric.shadows.ShadowLooper) COMMAND_SET_DEVICE_VOLUME(androidx.media3.common.Player.COMMAND_SET_DEVICE_VOLUME) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) TestPlayerRunHelper.runUntilSleepingForOffload(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.runUntilSleepingForOffload) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Listener(androidx.media3.common.Player.Listener) TestUtil.assertTimelinesSame(androidx.media3.test.utils.TestUtil.assertTimelinesSame) FakeShuffleOrder(androidx.media3.test.utils.FakeShuffleOrder) FakeMediaPeriod(androidx.media3.test.utils.FakeMediaPeriod) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito.never(org.mockito.Mockito.never) COMMAND_GET_AUDIO_ATTRIBUTES(androidx.media3.common.Player.COMMAND_GET_AUDIO_ATTRIBUTES) FakeVideoRenderer(androidx.media3.test.utils.FakeVideoRenderer) COMMAND_GET_DEVICE_VOLUME(androidx.media3.common.Player.COMMAND_GET_DEVICE_VOLUME) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) Mockito.reset(org.mockito.Mockito.reset) FakeMediaSourceFactory(androidx.media3.test.utils.FakeMediaSourceFactory) COMMAND_SET_VIDEO_SURFACE(androidx.media3.common.Player.COMMAND_SET_VIDEO_SURFACE) COMMAND_SEEK_TO_PREVIOUS(androidx.media3.common.Player.COMMAND_SEEK_TO_PREVIOUS) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) COMMAND_CHANGE_MEDIA_ITEMS(androidx.media3.common.Player.COMMAND_CHANGE_MEDIA_ITEMS) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Action(androidx.media3.test.utils.Action) Random(java.util.Random) MaskingMediaSource(androidx.media3.exoplayer.source.MaskingMediaSource) COMMAND_STOP(androidx.media3.common.Player.COMMAND_STOP) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) AudioAttributes(androidx.media3.common.AudioAttributes) ApplicationProvider(androidx.test.core.app.ApplicationProvider) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) FakeTrackSelector(androidx.media3.test.utils.FakeTrackSelector) ArgumentMatcher(org.mockito.ArgumentMatcher) END_OF_STREAM_ITEM(androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) COMMAND_SET_SPEED_AND_PITCH(androidx.media3.common.Player.COMMAND_SET_SPEED_AND_PITCH) FakeAdaptiveDataSet(androidx.media3.test.utils.FakeAdaptiveDataSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeMediaClockRenderer(androidx.media3.test.utils.FakeMediaClockRenderer) Mockito.atLeast(org.mockito.Mockito.atLeast) Assert.fail(org.junit.Assert.fail) FakeSampleStreamItem(androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem) MediaItem(androidx.media3.common.MediaItem) TestPlayerRunHelper.runUntilTimelineChanged(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.runUntilTimelineChanged) COMMAND_GET_TRACK_INFOS(androidx.media3.common.Player.COMMAND_GET_TRACK_INFOS) ServerSideAdInsertionMediaSource(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource) FakeChunkSource(androidx.media3.test.utils.FakeChunkSource) TestPlayerRunHelper.playUntilPosition(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.playUntilPosition) PlaybackException(androidx.media3.common.PlaybackException) TrackGroupArray(androidx.media3.common.TrackGroupArray) Util(androidx.media3.common.util.Util) Collectors(java.util.stream.Collectors) Format(androidx.media3.common.Format) COMMAND_SET_TRACK_SELECTION_PARAMETERS(androidx.media3.common.Player.COMMAND_SET_TRACK_SELECTION_PARAMETERS) COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM(androidx.media3.common.Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM) PlaybackParameters(androidx.media3.common.PlaybackParameters) List(java.util.List) FakeAdaptiveMediaSource(androidx.media3.test.utils.FakeAdaptiveMediaSource) TrackSelectionArray(androidx.media3.common.TrackSelectionArray) Mockito.inOrder(org.mockito.Mockito.inOrder) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) AdditionalMatchers.not(org.mockito.AdditionalMatchers.not) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TrackGroup(androidx.media3.common.TrackGroup) Context(android.content.Context) DEFAULT_WINDOW_DURATION_US(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US) COMMAND_SET_SHUFFLE_MODE(androidx.media3.common.Player.COMMAND_SET_SHUFFLE_MODE) COMMAND_GET_TEXT(androidx.media3.common.Player.COMMAND_GET_TEXT) Assert.assertThrows(org.junit.Assert.assertThrows) MediaMetadata(androidx.media3.common.MediaMetadata) Metadata(androidx.media3.common.Metadata) TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled) TracksInfo(androidx.media3.common.TracksInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestPlayerRunHelper.playUntilStartOfMediaItem(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem) Intent(android.content.Intent) COMMAND_PREPARE(androidx.media3.common.Player.COMMAND_PREPARE) FakeTimeline(androidx.media3.test.utils.FakeTimeline) AtomicReference(java.util.concurrent.atomic.AtomicReference) Shadows.shadowOf(org.robolectric.Shadows.shadowOf) ActionSchedule(androidx.media3.test.utils.ActionSchedule) AudioManager(android.media.AudioManager) FakeDataSource(androidx.media3.test.utils.FakeDataSource) HashSet(java.util.HashSet) COMMAND_SEEK_FORWARD(androidx.media3.common.Player.COMMAND_SEEK_FORWARD) COMMAND_SET_VOLUME(androidx.media3.common.Player.COMMAND_SET_VOLUME) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) PlayerTarget(androidx.media3.test.utils.ActionSchedule.PlayerTarget) ArgumentCaptor(org.mockito.ArgumentCaptor) ShadowAudioManager(org.robolectric.shadows.ShadowAudioManager) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) ImmutableList(com.google.common.collect.ImmutableList) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) Window(androidx.media3.common.Timeline.Window) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) RobolectricUtil.runMainLooperUntil(androidx.media3.test.utils.robolectric.RobolectricUtil.runMainLooperUntil) SurfaceTexture(android.graphics.SurfaceTexture) DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US) MediaSource(androidx.media3.exoplayer.source.MediaSource) InOrder(org.mockito.InOrder) COMMAND_SEEK_BACK(androidx.media3.common.Player.COMMAND_SEEK_BACK) MimeTypes(androidx.media3.common.MimeTypes) COMMAND_SEEK_TO_NEXT(androidx.media3.common.Player.COMMAND_SEEK_TO_NEXT) Clock(androidx.media3.common.util.Clock) Truth.assertThat(com.google.common.truth.Truth.assertThat) COMMAND_SET_MEDIA_ITEMS_METADATA(androidx.media3.common.Player.COMMAND_SET_MEDIA_ITEMS_METADATA) TestPlayerRunHelper.runUntilReceiveOffloadSchedulingEnabledNewState(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.runUntilReceiveOffloadSchedulingEnabledNewState) Mockito.verify(org.mockito.Mockito.verify) COMMAND_GET_VOLUME(androidx.media3.common.Player.COMMAND_GET_VOLUME) C(androidx.media3.common.C) Mockito(org.mockito.Mockito) PositionInfo(androidx.media3.common.Player.PositionInfo) FakeSampleStreamItem.oneByteSample(androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem.oneByteSample) STATE_ENDED(androidx.media3.common.Player.STATE_ENDED) MediaPeriod(androidx.media3.exoplayer.source.MediaPeriod) Collections(java.util.Collections) TestPlayerRunHelper.runUntilPlaybackState(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.runUntilPlaybackState) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) AtomicReference(java.util.concurrent.atomic.AtomicReference) FakeVideoRenderer(androidx.media3.test.utils.FakeVideoRenderer) Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) AdPlaybackState(androidx.media3.common.AdPlaybackState) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 13 with Player

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

the class ExoPlayerTest method cancelRepeatedMessageAfterDelivery.

@Test
public void cancelRepeatedMessageAfterDelivery() throws Exception {
    final CountingMessageTarget target = new CountingMessageTarget();
    final AtomicReference<PlayerMessage> message = new AtomicReference<>();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            message.set(player.createMessage(target).setPosition(/* positionMs= */
            50).setDeleteAfterDelivery(/* deleteAfterDelivery= */
            false).send());
        }
    }).playUntilPosition(/* mediaItemIndex= */
    0, /* positionMs= */
    51).seek(/* positionMs= */
    0).executeRunnable(() -> message.get().cancel()).play().build();
    new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(message.get().isCanceled()).isTrue();
    assertThat(target.messageCount).isEqualTo(1);
}
Also used : ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 14 with Player

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

the class ExoPlayerTest method setMediaSources_whenEmpty_invalidInitialSeek_correctMasking.

@Test
public void setMediaSources_whenEmpty_invalidInitialSeek_correctMasking() throws Exception {
    final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET };
    final long[] currentPositions = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    final long[] bufferedPositions = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPositionDiscontinuity().waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
            currentPositions[0] = player.getCurrentPosition();
            bufferedPositions[0] = player.getBufferedPosition();
            // Increase current media item index.
            player.addMediaSource(/* index= */
            0, new FakeMediaSource());
            currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
            currentPositions[1] = player.getCurrentPosition();
            bufferedPositions[1] = player.getBufferedPosition();
        }
    }).prepare().waitForTimelineChanged().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndices[2] = player.getCurrentMediaItemIndex();
            currentPositions[2] = player.getCurrentPosition();
            bufferedPositions[2] = player.getBufferedPosition();
        }
    }).waitForPlaybackState(Player.STATE_ENDED).build();
    new ExoPlayerTestRunner.Builder(context).initialSeek(/* mediaItemIndex= */
    1, 2000).setMediaSources(new FakeMediaSource()).setActionSchedule(actionSchedule).build().start(/* doPrepare= */
    false).blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertArrayEquals(new int[] { 0, 1, 1 }, currentMediaItemIndices);
    assertArrayEquals(new long[] { 0, 0, 0 }, currentPositions);
    assertArrayEquals(new long[] { 0, 0, 0 }, bufferedPositions);
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Test(org.junit.Test)

Example 15 with Player

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

the class ExoPlayerTest method setPlaybackSpeedBeforePreparationCompletesSucceeds.

@Test
public void setPlaybackSpeedBeforePreparationCompletesSucceeds() throws Exception {
    // Test that no exception is thrown when playback parameters are updated between creating a
    // period and preparation of the period completing.
    final CountDownLatch createPeriodCalledCountDownLatch = new CountDownLatch(1);
    final FakeMediaPeriod[] fakeMediaPeriodHolder = new FakeMediaPeriod[1];
    MediaSource mediaSource = 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) {
            // Defer completing preparation of the period until playback parameters have been set.
            fakeMediaPeriodHolder[0] = new FakeMediaPeriod(trackGroupArray, allocator, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
            true);
            createPeriodCalledCountDownLatch.countDown();
            return fakeMediaPeriodHolder[0];
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            try {
                player.getClock().onThreadBlocked();
                createPeriodCalledCountDownLatch.await();
            } catch (InterruptedException e) {
                throw new IllegalStateException(e);
            }
        }
    }).setPlaybackParameters(new PlaybackParameters(/* speed= */
    2f)).executeRunnable(() -> fakeMediaPeriodHolder[0].setPreparationComplete()).build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
}
Also used : TransferListener(androidx.media3.datasource.TransferListener) Allocator(androidx.media3.exoplayer.upstream.Allocator) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) TrackGroupArray(androidx.media3.common.TrackGroupArray) CountDownLatch(java.util.concurrent.CountDownLatch) 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) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) PlaybackParameters(androidx.media3.common.PlaybackParameters) 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