Search in sources :

Example 11 with FakeShuffleOrder

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

the class ConcatenatingMediaSourceTest method setUp.

@Before
public void setUp() throws Exception {
    mediaSource = new ConcatenatingMediaSource(/* isAtomic= */
    false, new FakeShuffleOrder(0));
    testRunner = new MediaSourceTestRunner(mediaSource, null);
}
Also used : MediaSourceTestRunner(androidx.media3.test.utils.MediaSourceTestRunner) FakeShuffleOrder(androidx.media3.test.utils.FakeShuffleOrder) Before(org.junit.Before)

Example 12 with FakeShuffleOrder

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

the class ExoPlayerTest method sendMessagesNonLinearPeriodOrder.

@Test
public void sendMessagesNonLinearPeriodOrder() throws Exception {
    Timeline fakeTimeline = new FakeTimeline();
    MediaSource[] fakeMediaSources = { new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT) };
    ConcatenatingMediaSource mediaSource = new ConcatenatingMediaSource(false, new FakeShuffleOrder(3), fakeMediaSources);
    PositionGrabbingMessageTarget target1 = new PositionGrabbingMessageTarget();
    PositionGrabbingMessageTarget target2 = new PositionGrabbingMessageTarget();
    PositionGrabbingMessageTarget target3 = new PositionGrabbingMessageTarget();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).sendMessage(target1, /* mediaItemIndex = */
    0, /* positionMs= */
    50).sendMessage(target2, /* mediaItemIndex = */
    1, /* positionMs= */
    50).sendMessage(target3, /* mediaItemIndex = */
    2, /* positionMs= */
    50).setShuffleModeEnabled(true).seek(/* mediaItemIndex= */
    2, /* positionMs= */
    0).play().build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(target1.mediaItemIndex).isEqualTo(0);
    assertThat(target2.mediaItemIndex).isEqualTo(1);
    assertThat(target3.mediaItemIndex).isEqualTo(2);
}
Also used : Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) 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) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) FakeTimeline(androidx.media3.test.utils.FakeTimeline) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) FakeShuffleOrder(androidx.media3.test.utils.FakeShuffleOrder) Test(org.junit.Test)

Example 13 with FakeShuffleOrder

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

the class ExoPlayerTest method setShuffleModeEnabled_notifiesAvailableCommandsChanged.

@Test
public void setShuffleModeEnabled_notifiesAvailableCommandsChanged() {
    Player.Commands commandsWithSeekToPreviousWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM);
    Player.Commands commandsWithSeekToNextWindow = createWithDefaultCommands(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT);
    Player.Listener mockListener = mock(Player.Listener.class);
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addListener(mockListener);
    MediaSource mediaSource = new ConcatenatingMediaSource(false, new FakeShuffleOrder(/* length= */
    2), new FakeMediaSource(), new FakeMediaSource());
    player.addMediaSource(mediaSource);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    player.setShuffleModeEnabled(true);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
Also used : Listener(androidx.media3.common.Player.Listener) Player(androidx.media3.common.Player) 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) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) FakeShuffleOrder(androidx.media3.test.utils.FakeShuffleOrder) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 14 with FakeShuffleOrder

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

the class ExoPlayerTest method resetMediaSourcesWithPositionResetAndShufflingUsesFirstPeriod.

@Test
public void resetMediaSourcesWithPositionResetAndShufflingUsesFirstPeriod() throws Exception {
    Timeline fakeTimeline = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    100000));
    ConcatenatingMediaSource firstMediaSource = new ConcatenatingMediaSource(/* isAtomic= */
    false, new FakeShuffleOrder(/* length= */
    2), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT));
    ConcatenatingMediaSource secondMediaSource = new ConcatenatingMediaSource(/* isAtomic= */
    false, new FakeShuffleOrder(/* length= */
    2), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT));
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).setShuffleModeEnabled(true).setMediaSources(/* resetPosition= */
    true, secondMediaSource).play().waitForPositionDiscontinuity().build();
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(firstMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    testRunner.assertPlayedPeriodIndices(0, 1, 0);
}
Also used : Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) 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) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) FakeShuffleOrder(androidx.media3.test.utils.FakeShuffleOrder) Test(org.junit.Test)

Example 15 with FakeShuffleOrder

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

the class ExoPlayerTest method restartAfterEmptyTimelineWithShuffleModeEnabledUsesCorrectFirstPeriod.

@Test
public void restartAfterEmptyTimelineWithShuffleModeEnabledUsesCorrectFirstPeriod() throws Exception {
    ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(/* isAtomic= */
    false, new FakeShuffleOrder(0));
    AtomicInteger mediaItemIndexAfterAddingSources = new AtomicInteger();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).setShuffleModeEnabled(true).waitForPlaybackState(Player.STATE_ENDED).executeRunnable(() -> concatenatingMediaSource.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()))).waitForTimelineChanged().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            mediaItemIndexAfterAddingSources.set(player.getCurrentMediaItemIndex());
        }
    }).build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(concatenatingMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertThat(mediaItemIndexAfterAddingSources.get()).isEqualTo(1);
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) FakeShuffleOrder(androidx.media3.test.utils.FakeShuffleOrder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 FakeShuffleOrder (androidx.media3.test.utils.FakeShuffleOrder)15 Timeline (androidx.media3.common.Timeline)14 FakeTimeline (androidx.media3.test.utils.FakeTimeline)9 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)7 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)5 ActionSchedule (androidx.media3.test.utils.ActionSchedule)5 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)5 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)4 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)3 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)3 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)3 MediaSource (androidx.media3.exoplayer.source.MediaSource)3 ShuffleOrder (androidx.media3.exoplayer.source.ShuffleOrder)3 ServerSideAdInsertionMediaSource (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource)3 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)3 FakeAdaptiveMediaSource (androidx.media3.test.utils.FakeAdaptiveMediaSource)3 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)3 PlayerRunnable (androidx.media3.test.utils.ActionSchedule.PlayerRunnable)2 MediaSourceTestRunner (androidx.media3.test.utils.MediaSourceTestRunner)2