Search in sources :

Example 1 with COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM

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

the class TimelineQueueNavigator method getSupportedQueueNavigatorActions.

@Override
public long getSupportedQueueNavigatorActions(Player player) {
    boolean enableSkipTo = false;
    boolean enablePrevious = false;
    boolean enableNext = false;
    Timeline timeline = player.getCurrentTimeline();
    if (!timeline.isEmpty() && !player.isPlayingAd()) {
        timeline.getWindow(player.getCurrentMediaItemIndex(), window);
        enableSkipTo = timeline.getWindowCount() > 1;
        enablePrevious = player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM) || !window.isLive() || player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM);
        enableNext = (window.isLive() && window.isDynamic) || player.isCommandAvailable(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM);
    }
    long actions = 0;
    if (enableSkipTo) {
        actions |= PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM;
    }
    if (enablePrevious) {
        actions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
    }
    if (enableNext) {
        actions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT;
    }
    return actions;
}
Also used : Timeline(com.google.android.exoplayer2.Timeline)

Example 2 with COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM

use of com.google.android.exoplayer2.Player.COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM 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)

Example 3 with COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM

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

the class PlayerControlView 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);
    }
    updateButton(showPreviousButton, enablePrevious, previousButton);
    updateButton(showRewindButton, enableRewind, rewindButton);
    updateButton(showFastForwardButton, enableFastForward, fastForwardButton);
    updateButton(showNextButton, enableNext, nextButton);
    if (timeBar != null) {
        timeBar.setEnabled(enableSeeking);
    }
}
Also used : Player(com.google.android.exoplayer2.Player) Nullable(androidx.annotation.Nullable)

Example 4 with COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM

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

the class MediaSessionConnector method buildPlaybackActions.

private long buildPlaybackActions(Player player) {
    boolean enableSeeking = player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM);
    boolean enableRewind = player.isCommandAvailable(COMMAND_SEEK_BACK);
    boolean enableFastForward = player.isCommandAvailable(COMMAND_SEEK_FORWARD);
    boolean enableSetRating = false;
    boolean enableSetCaptioningEnabled = false;
    Timeline timeline = player.getCurrentTimeline();
    if (!timeline.isEmpty() && !player.isPlayingAd()) {
        enableSetRating = ratingCallback != null;
        enableSetCaptioningEnabled = captionCallback != null && captionCallback.hasCaptions(player);
    }
    long playbackActions = BASE_PLAYBACK_ACTIONS;
    if (enableSeeking) {
        playbackActions |= PlaybackStateCompat.ACTION_SEEK_TO;
    }
    if (enableFastForward) {
        playbackActions |= PlaybackStateCompat.ACTION_FAST_FORWARD;
    }
    if (enableRewind) {
        playbackActions |= PlaybackStateCompat.ACTION_REWIND;
    }
    playbackActions &= enabledPlaybackActions;
    long actions = playbackActions;
    if (queueNavigator != null) {
        actions |= (QueueNavigator.ACTIONS & queueNavigator.getSupportedQueueNavigatorActions(player));
    }
    if (enableSetRating) {
        actions |= PlaybackStateCompat.ACTION_SET_RATING;
    }
    if (enableSetCaptioningEnabled) {
        actions |= PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED;
    }
    return actions;
}
Also used : Timeline(com.google.android.exoplayer2.Timeline)

Example 5 with COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM

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

the class ExoPlayerTest method isCommandAvailable_duringUnseekableItem_isFalseForSeekInCurrentCommands.

@Test
public void isCommandAvailable_duringUnseekableItem_isFalseForSeekInCurrentCommands() throws Exception {
    Timeline timelineWithUnseekableWindow = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
    false, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(10_000)));
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSource(new FakeMediaSource(timelineWithUnseekableWindow));
    player.prepare();
    runUntilPlaybackState(player, Player.STATE_READY);
    assertThat(player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_BACK)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_FORWARD)).isFalse();
}
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)5 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)4 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)4 Nullable (androidx.annotation.Nullable)2 Player (com.google.android.exoplayer2.Player)2 Timeline (com.google.android.exoplayer2.Timeline)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 MediaItem (com.google.android.exoplayer2.MediaItem)1 Listener (com.google.android.exoplayer2.Player.Listener)1 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)1 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)1