Search in sources :

Example 6 with COMMAND_SEEK_TO_NEXT_MEDIA_ITEM

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

the class ExoPlayerTest method removeMediaItem_current_notifiesAvailableCommandsChanged.

@Test
public void removeMediaItem_current_notifiesAvailableCommandsChanged() {
    Player.Commands defaultCommands = createWithDefaultCommands();
    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);
    player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()));
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    player.removeMediaItem(/* index= */
    0);
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
Also used : Listener(androidx.media3.common.Player.Listener) Player(androidx.media3.common.Player) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 7 with COMMAND_SEEK_TO_NEXT_MEDIA_ITEM

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

the class ExoPlayerTest method seekTo_nextWindow_notifiesAvailableCommandsChanged.

@Test
public void seekTo_nextWindow_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.Commands commandsWithSeekToPreviousAndNextWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, 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);
    player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource(), new FakeMediaSource(), new FakeMediaSource()));
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    player.seekTo(/* mediaItemIndex= */
    1, /* positionMs= */
    0);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousAndNextWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    player.seekTo(/* mediaItemIndex= */
    2, /* positionMs= */
    0);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    player.seekTo(/* mediaItemIndex= */
    3, /* positionMs= */
    0);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
    verify(mockListener, times(3)).onAvailableCommandsChanged(any());
}
Also used : Listener(androidx.media3.common.Player.Listener) Player(androidx.media3.common.Player) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 8 with COMMAND_SEEK_TO_NEXT_MEDIA_ITEM

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

the class CastPlayerTest method addMediaItem_atTheEnd_notifiesAvailableCommandsChanged.

@Test
public void addMediaItem_atTheEnd_notifiesAvailableCommandsChanged() {
    Player.Commands defaultCommands = createWithDefaultCommands();
    Player.Commands commandsWithSeekToNextWindow = createWithDefaultCommands(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT);
    MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
    1);
    MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
    2);
    MediaItem mediaItem3 = createMediaItem(/* mediaQueueItemId= */
    3);
    castPlayer.addMediaItem(mediaItem1);
    updateTimeLine(ImmutableList.of(mediaItem1), /* mediaQueueItemIds= */
    new int[] { 1 }, /* currentItemId= */
    1);
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    castPlayer.addMediaItem(mediaItem2);
    updateTimeLine(ImmutableList.of(mediaItem1, mediaItem2), /* mediaQueueItemIds= */
    new int[] { 1, 2 }, /* currentItemId= */
    1);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    castPlayer.addMediaItem(mediaItem3);
    updateTimeLine(ImmutableList.of(mediaItem1, mediaItem2, mediaItem3), /* mediaQueueItemIds= */
    new int[] { 1, 2, 3 }, /* currentItemId= */
    1);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
Also used : Player(androidx.media3.common.Player) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 9 with COMMAND_SEEK_TO_NEXT_MEDIA_ITEM

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

the class ExoPlayerTest method seekTo_previousWindow_notifiesAvailableCommandsChanged.

@Test
public void seekTo_previousWindow_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.Commands commandsWithSeekToPreviousAndNextWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, 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);
    player.seekTo(/* mediaItemIndex= */
    3, /* positionMs= */
    0);
    player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource(), new FakeMediaSource(), new FakeMediaSource()));
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    player.seekTo(/* mediaItemIndex= */
    2, /* positionMs= */
    0);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousAndNextWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    player.seekTo(/* mediaItemIndex= */
    1, /* positionMs= */
    0);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    player.seekTo(/* mediaItemIndex= */
    0, /* positionMs= */
    0);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow);
    verify(mockListener, times(3)).onAvailableCommandsChanged(any());
}
Also used : Listener(androidx.media3.common.Player.Listener) Player(androidx.media3.common.Player) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 10 with COMMAND_SEEK_TO_NEXT_MEDIA_ITEM

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

Aggregations

Test (org.junit.Test)13 Player (androidx.media3.common.Player)11 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)10 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)10 Listener (androidx.media3.common.Player.Listener)8 MediaItem (androidx.media3.common.MediaItem)3 AdPlaybackState (androidx.media3.common.AdPlaybackState)1 Timeline (androidx.media3.common.Timeline)1 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)1 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)1 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)1 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)1 MediaSource (androidx.media3.exoplayer.source.MediaSource)1 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)1 ServerSideAdInsertionMediaSource (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource)1 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)1 FakeAdaptiveMediaSource (androidx.media3.test.utils.FakeAdaptiveMediaSource)1 FakeShuffleOrder (androidx.media3.test.utils.FakeShuffleOrder)1 FakeTimeline (androidx.media3.test.utils.FakeTimeline)1 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)1