Search in sources :

Example 11 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_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);
    MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
    1);
    MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
    2);
    castPlayer.addMediaItems(ImmutableList.of(mediaItem1, mediaItem2));
    updateTimeLine(ImmutableList.of(mediaItem1, mediaItem2), /* mediaQueueItemIds= */
    new int[] { 1, 2 }, /* currentItemId= */
    1);
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    castPlayer.removeMediaItem(/* index= */
    0);
    updateTimeLine(ImmutableList.of(mediaItem2), /* mediaQueueItemIds= */
    new int[] { 2 }, /* currentItemId= */
    2);
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
Also used : Player(com.google.android.exoplayer2.Player) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 12 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 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(com.google.android.exoplayer2.Player) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 13 with COMMAND_SEEK_TO_NEXT

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

the class StyledPlayerControlView method updateNavigation.

private void updateNavigation() {
    if (!isVisible() || !isAttachedToWindow) {
        return;
    }
    @Nullable Player player = this.player;
    boolean enableSeeking = false;
    boolean enablePrevious = false;
    boolean enableRewind = false;
    boolean enableFastForward = false;
    boolean enableNext = false;
    if (player != null) {
        enableSeeking = player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM);
        enablePrevious = player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS);
        enableRewind = player.isCommandAvailable(COMMAND_SEEK_BACK);
        enableFastForward = player.isCommandAvailable(COMMAND_SEEK_FORWARD);
        enableNext = player.isCommandAvailable(COMMAND_SEEK_TO_NEXT);
    }
    if (enableRewind) {
        updateRewindButton();
    }
    if (enableFastForward) {
        updateFastForwardButton();
    }
    updateButton(enablePrevious, previousButton);
    updateButton(enableRewind, rewindButton);
    updateButton(enableFastForward, fastForwardButton);
    updateButton(enableNext, nextButton);
    if (timeBar != null) {
        timeBar.setEnabled(enableSeeking);
    }
}
Also used : Player(com.google.android.exoplayer2.Player) ForwardingPlayer(com.google.android.exoplayer2.ForwardingPlayer) Nullable(androidx.annotation.Nullable)

Example 14 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 addMediaSource_atTheEnd_notifiesAvailableCommandsChanged.

@Test
public void addMediaSource_atTheEnd_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.addMediaSource(new FakeMediaSource());
    verify(mockListener).onAvailableCommandsChanged(defaultCommands);
    // Check that there were no other calls to onAvailableCommandsChanged.
    verify(mockListener).onAvailableCommandsChanged(any());
    player.addMediaSource(new FakeMediaSource());
    verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow);
    verify(mockListener, times(2)).onAvailableCommandsChanged(any());
    player.addMediaSource(new FakeMediaSource());
    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 15 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 isCommandAvailable_duringLiveItem_isTrueForSeekToNext.

@Test
public void isCommandAvailable_duringLiveItem_isTrueForSeekToNext() throws Exception {
    Timeline timelineWithLiveWindow = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    true, /* isLive= */
    true, /* isPlaceholder= */
    false, /* durationUs= */
    C.TIME_UNSET, /* defaultPositionUs= */
    10_000_000, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, AdPlaybackState.NONE));
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSource(new FakeMediaSource(timelineWithLiveWindow));
    player.prepare();
    runUntilPlaybackState(player, Player.STATE_READY);
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_NEXT)).isTrue();
}
Also used : NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) 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