Search in sources :

Example 1 with COMMAND_SEEK_TO_NEXT

use of com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT in project ExoPlayer by google.

the class CastPlayerTest method removeMediaItem_atTheEnd_notifiesAvailableCommandsChanged.

@Test
public void removeMediaItem_atTheEnd_notifiesAvailableCommandsChanged() {
    Player.Commands defaultCommands = createWithDefaultCommands();
    Player.Commands commandsWithSeekToNextWindow = createWithDefaultCommands(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT);
    Player.Commands emptyTimelineCommands = createWithDefaultCommands(/* isTimelineEmpty= */
    true);
    MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
    1);
    MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
    2);
    MediaItem mediaItem3 = createMediaItem(/* mediaQueueItemId= */
    3);
    castPlayer.addMediaItems(ImmutableList.of(mediaItem1, mediaItem2, mediaItem3));
    updateTimeLine(ImmutableList.of(mediaItem1, mediaItem2, mediaItem3), /* mediaQueueItemIds= */
    new int[] { 1, 2, 3 }, /* currentItemId= */
    1);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    castPlayer.removeMediaItem(/* index= */
    2);
    updateTimeLine(ImmutableList.of(mediaItem1, mediaItem2), /* mediaQueueItemIds= */
    new int[] { 1, 2 }, /* currentItemId= */
    1);
    verify(mockListener).onAvailableCommandsChanged(any());
    castPlayer.removeMediaItem(/* index= */
    1);
    updateTimeLine(ImmutableList.of(mediaItem1), /* mediaQueueItemIds= */
    new int[] { 1 }, /* currentItemId= */
    1);
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    castPlayer.removeMediaItem(/* index= */
    0);
    updateTimeLine(ImmutableList.of(), /* mediaQueueItemIds= */
    new int[0], /* currentItemId= */
    C.INDEX_UNSET);
    verify(mockListener).onAvailableCommandsChanged(emptyTimelineCommands);
    verify(mockListener, times(3)).onAvailableCommandsChanged(any());
}
Also used : Player(com.google.android.exoplayer2.Player) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 2 with COMMAND_SEEK_TO_NEXT

use of com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT in project ExoPlayer by google.

the class CastPlayerTest method isCommandAvailable_duringLiveItem_isTrueForSeekToNext.

@Test
public void isCommandAvailable_duringLiveItem_isTrueForSeekToNext() {
    MediaItem mediaItem = createMediaItem(/* mediaQueueItemId= */
    1);
    List<MediaItem> mediaItems = ImmutableList.of(mediaItem);
    int[] mediaQueueItemIds = new int[] { 1 };
    int[] streamTypes = new int[] { MediaInfo.STREAM_TYPE_LIVE };
    long[] durationsMs = new long[] { C.TIME_UNSET };
    castPlayer.addMediaItem(mediaItem);
    updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
    1, streamTypes, durationsMs, /* positionMs= */
    C.TIME_UNSET);
    assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_TO_NEXT)).isTrue();
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 3 with COMMAND_SEEK_TO_NEXT

use of com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT in project ExoPlayer by google.

the class ExoPlayerTest method setRepeatMode_all_notifiesAvailableCommandsChanged.

@Test
public void setRepeatMode_all_notifiesAvailableCommandsChanged() {
    Player.Commands defaultCommands = createWithDefaultCommands();
    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.addMediaSource(new FakeMediaSource());
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    player.setRepeatMode(Player.REPEAT_MODE_ALL);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousAndNextWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 4 with COMMAND_SEEK_TO_NEXT

use of com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT in project ExoPlayer by google.

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(com.google.android.exoplayer2.Player.Listener) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) FakeShuffleOrder(com.google.android.exoplayer2.testutil.FakeShuffleOrder) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 5 with COMMAND_SEEK_TO_NEXT

use of com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT in project ExoPlayer by google.

the class ExoPlayerTest method automaticWindowTransition_notifiesAvailableCommandsChanged.

@Test
public void automaticWindowTransition_notifiesAvailableCommandsChanged() throws Exception {
    Player.Commands commandsWithSeekToNextWindow = createWithDefaultCommands(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT);
    Player.Commands commandsWithSeekInCurrentAndToNextWindow = createWithDefaultCommands(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT, COMMAND_SEEK_BACK, COMMAND_SEEK_FORWARD);
    Player.Commands commandsWithSeekInCurrentAndToPreviousWindow = createWithDefaultCommands(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, COMMAND_SEEK_BACK, COMMAND_SEEK_FORWARD);
    Player.Commands commandsWithSeekAnywhere = createWithDefaultCommands(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT, COMMAND_SEEK_BACK, COMMAND_SEEK_FORWARD);
    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.prepare();
    runUntilPlaybackState(player, Player.STATE_READY);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekInCurrentAndToNextWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    playUntilStartOfMediaItem(player, /* mediaItemIndex= */
    1);
    runUntilPendingCommandsAreFullyHandled(player);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekAnywhere);
    verify(mockListener, times(3)).onAvailableCommandsChanged(any());
    playUntilStartOfMediaItem(player, /* mediaItemIndex= */
    2);
    runUntilPendingCommandsAreFullyHandled(player);
    verify(mockListener, times(3)).onAvailableCommandsChanged(any());
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekInCurrentAndToPreviousWindow);
    verify(mockListener, times(4)).onAvailableCommandsChanged(any());
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)11 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)11 Listener (com.google.android.exoplayer2.Player.Listener)8 Player (com.google.android.exoplayer2.Player)5 MediaItem (com.google.android.exoplayer2.MediaItem)4 Nullable (androidx.annotation.Nullable)2 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)2 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)2 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)2 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)2 ForwardingPlayer (com.google.android.exoplayer2.ForwardingPlayer)1 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)1 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)1 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)1 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)1 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)1 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)1