use of androidx.media3.common.Player.COMMAND_SEEK_BACK in project media by androidx.
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);
}
if (enableRewind) {
updateRewindButton();
}
if (enableFastForward) {
updateFastForwardButton();
}
updateButton(enablePrevious, previousButton);
updateButton(enableRewind, rewindButton);
updateButton(enableFastForward, fastForwardButton);
updateButton(enableNext, nextButton);
if (timeBar != null) {
timeBar.setEnabled(enableSeeking);
}
}
use of androidx.media3.common.Player.COMMAND_SEEK_BACK in project media by androidx.
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 androidx.media3.common.Player.COMMAND_SEEK_BACK in project media by androidx.
the class ExoPlayerTest method isCommandAvailable_duringAd_isFalseForSeekCommands.
@Test
public void isCommandAvailable_duringAd_isFalseForSeekCommands() throws Exception {
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
new Object(), /* adGroupTimesUs...= */
0).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).withAdUri(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, Uri.EMPTY).withAdDurationsUs(/* adDurationUs= */
new long[][] { { Util.msToUs(4_000) } });
Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(10_000), adPlaybackState));
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource(adTimeline), new FakeMediaSource()));
player.seekTo(/* mediaItemIndex= */
1, /* positionMs= */
0);
player.prepare();
runUntilPlaybackState(player, Player.STATE_READY);
assertThat(player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)).isFalse();
assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM)).isFalse();
assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS)).isFalse();
assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM)).isFalse();
assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_NEXT)).isFalse();
assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_MEDIA_ITEM)).isFalse();
assertThat(player.isCommandAvailable(COMMAND_SEEK_BACK)).isFalse();
assertThat(player.isCommandAvailable(COMMAND_SEEK_FORWARD)).isFalse();
}
Aggregations