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;
}
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());
}
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);
}
}
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;
}
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();
}
Aggregations