Search in sources :

Example 6 with COMMAND_SEEK_BACK

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);
    }
}
Also used : ForwardingPlayer(androidx.media3.common.ForwardingPlayer) Player(androidx.media3.common.Player) Nullable(androidx.annotation.Nullable)

Example 7 with COMMAND_SEEK_BACK

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());
}
Also used : Listener(androidx.media3.common.Player.Listener) Player(androidx.media3.common.Player) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 8 with COMMAND_SEEK_BACK

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();
}
Also used : Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) AdPlaybackState(androidx.media3.common.AdPlaybackState) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 Player (androidx.media3.common.Player)4 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)4 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)4 Nullable (androidx.annotation.Nullable)2 Timeline (androidx.media3.common.Timeline)2 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)2 FakeTimeline (androidx.media3.test.utils.FakeTimeline)2 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)2 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)2 AdPlaybackState (androidx.media3.common.AdPlaybackState)1 ForwardingPlayer (androidx.media3.common.ForwardingPlayer)1 MediaItem (androidx.media3.common.MediaItem)1 Listener (androidx.media3.common.Player.Listener)1 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)1 ArrayList (java.util.ArrayList)1