Search in sources :

Example 1 with RepeatMode

use of androidx.media3.common.Player.RepeatMode in project media by androidx.

the class CastPlayer method setMediaItemsInternal.

@Nullable
private PendingResult<MediaChannelResult> setMediaItemsInternal(MediaQueueItem[] mediaQueueItems, int startIndex, long startPositionMs, @RepeatMode int repeatMode) {
    if (remoteMediaClient == null || mediaQueueItems.length == 0) {
        return null;
    }
    startPositionMs = startPositionMs == C.TIME_UNSET ? 0 : startPositionMs;
    if (startIndex == C.INDEX_UNSET) {
        startIndex = getCurrentMediaItemIndex();
        startPositionMs = getCurrentPosition();
    }
    Timeline currentTimeline = getCurrentTimeline();
    if (!currentTimeline.isEmpty()) {
        pendingMediaItemRemovalPosition = getCurrentPositionInfo();
    }
    return remoteMediaClient.queueLoad(mediaQueueItems, min(startIndex, mediaQueueItems.length - 1), getCastRepeatMode(repeatMode), startPositionMs, /* customData= */
    null);
}
Also used : Timeline(androidx.media3.common.Timeline) Nullable(androidx.annotation.Nullable)

Example 2 with RepeatMode

use of androidx.media3.common.Player.RepeatMode in project media by androidx.

the class ExoPlayerTest method onEvents_correspondToListenerCalls.

@Test
public void onEvents_correspondToListenerCalls() throws Exception {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    Player.Listener listener = mock(Player.Listener.class);
    player.addListener(listener);
    Format formatWithStaticMetadata = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_H264).setMetadata(new Metadata(new BinaryFrame(/* id= */
    "", /* data= */
    new byte[0]), new TextInformationFrame(/* id= */
    "TT2", /* description= */
    null, /* value= */
    "title"))).build();
    // Set multiple values together.
    player.setMediaSource(new FakeMediaSource(new FakeTimeline(), formatWithStaticMetadata));
    player.seekTo(2_000);
    player.setPlaybackParameters(new PlaybackParameters(/* speed= */
    2.0f));
    runUntilPendingCommandsAreFullyHandled(player);
    verify(listener).onTimelineChanged(any(), anyInt());
    verify(listener).onMediaItemTransition(any(), anyInt());
    verify(listener).onPositionDiscontinuity(any(), any(), anyInt());
    verify(listener).onPlaybackParametersChanged(any());
    ArgumentCaptor<Player.Events> eventCaptor = ArgumentCaptor.forClass(Player.Events.class);
    verify(listener).onEvents(eq(player), eventCaptor.capture());
    Player.Events events = eventCaptor.getValue();
    assertThat(events.contains(Player.EVENT_TIMELINE_CHANGED)).isTrue();
    assertThat(events.contains(Player.EVENT_MEDIA_ITEM_TRANSITION)).isTrue();
    assertThat(events.contains(Player.EVENT_POSITION_DISCONTINUITY)).isTrue();
    assertThat(events.contains(Player.EVENT_PLAYBACK_PARAMETERS_CHANGED)).isTrue();
    // Set values recursively.
    player.addListener(new Player.Listener() {

        @Override
        public void onRepeatModeChanged(int repeatMode) {
            player.setShuffleModeEnabled(true);
        }
    });
    player.setRepeatMode(Player.REPEAT_MODE_ONE);
    runUntilPendingCommandsAreFullyHandled(player);
    verify(listener).onRepeatModeChanged(anyInt());
    verify(listener).onShuffleModeEnabledChanged(anyBoolean());
    verify(listener, times(2)).onEvents(eq(player), eventCaptor.capture());
    events = Iterables.getLast(eventCaptor.getAllValues());
    assertThat(events.contains(Player.EVENT_REPEAT_MODE_CHANGED)).isTrue();
    assertThat(events.contains(Player.EVENT_SHUFFLE_MODE_ENABLED_CHANGED)).isTrue();
    // Ensure all other events are called (even though we can't control how exactly they are
    // combined together in onEvents calls).
    player.prepare();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
    player.play();
    player.setMediaItem(MediaItem.fromUri("http://this-will-throw-an-exception.mp4"));
    TestPlayerRunHelper.runUntilError(player);
    runUntilPendingCommandsAreFullyHandled(player);
    player.release();
    // Verify that all callbacks have been called at least once.
    verify(listener, atLeastOnce()).onTimelineChanged(any(), anyInt());
    verify(listener, atLeastOnce()).onMediaItemTransition(any(), anyInt());
    verify(listener, atLeastOnce()).onPositionDiscontinuity(any(), any(), anyInt());
    verify(listener, atLeastOnce()).onPlaybackParametersChanged(any());
    verify(listener, atLeastOnce()).onRepeatModeChanged(anyInt());
    verify(listener, atLeastOnce()).onShuffleModeEnabledChanged(anyBoolean());
    verify(listener, atLeastOnce()).onPlaybackStateChanged(anyInt());
    verify(listener, atLeastOnce()).onIsLoadingChanged(anyBoolean());
    verify(listener, atLeastOnce()).onTracksChanged(any(), any());
    verify(listener, atLeastOnce()).onMediaMetadataChanged(any());
    verify(listener, atLeastOnce()).onPlayWhenReadyChanged(anyBoolean(), anyInt());
    verify(listener, atLeastOnce()).onIsPlayingChanged(anyBoolean());
    verify(listener, atLeastOnce()).onPlayerErrorChanged(any());
    verify(listener, atLeastOnce()).onPlayerError(any());
    // Verify all the same events have been recorded with onEvents.
    verify(listener, atLeastOnce()).onEvents(eq(player), eventCaptor.capture());
    List<Player.Events> allEvents = eventCaptor.getAllValues();
    assertThat(containsEvent(allEvents, Player.EVENT_TIMELINE_CHANGED)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_MEDIA_ITEM_TRANSITION)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_POSITION_DISCONTINUITY)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_PLAYBACK_PARAMETERS_CHANGED)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_REPEAT_MODE_CHANGED)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_SHUFFLE_MODE_ENABLED_CHANGED)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_PLAYBACK_STATE_CHANGED)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_IS_LOADING_CHANGED)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_TRACKS_CHANGED)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_MEDIA_METADATA_CHANGED)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_PLAY_WHEN_READY_CHANGED)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_IS_PLAYING_CHANGED)).isTrue();
    assertThat(containsEvent(allEvents, Player.EVENT_PLAYER_ERROR)).isTrue();
}
Also used : Player(androidx.media3.common.Player) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) MediaMetadata(androidx.media3.common.MediaMetadata) Metadata(androidx.media3.common.Metadata) TextInformationFrame(androidx.media3.extractor.metadata.id3.TextInformationFrame) Listener(androidx.media3.common.Player.Listener) Format(androidx.media3.common.Format) BinaryFrame(androidx.media3.extractor.metadata.id3.BinaryFrame) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) PlaybackParameters(androidx.media3.common.PlaybackParameters) Test(org.junit.Test)

Example 3 with RepeatMode

use of androidx.media3.common.Player.RepeatMode in project media by androidx.

the class PlayerInfo method fromBundle.

private static PlayerInfo fromBundle(Bundle bundle) {
    @Nullable PlaybackException playerError = BundleableUtil.fromNullableBundle(PlaybackException.CREATOR, bundle.getBundle(keyForField(FIELD_PLAYBACK_ERROR)));
    int mediaItemTransitionReason = bundle.getInt(keyForField(FIELD_MEDIA_ITEM_TRANSITION_REASON), MEDIA_ITEM_TRANSITION_REASON_REPEAT);
    SessionPositionInfo sessionPositionInfo = BundleableUtil.fromNullableBundle(SessionPositionInfo.CREATOR, bundle.getBundle(keyForField(FIELD_SESSION_POSITION_INFO)), SessionPositionInfo.DEFAULT);
    PositionInfo oldPositionInfo = BundleableUtil.fromNullableBundle(PositionInfo.CREATOR, bundle.getBundle(keyForField(FIELD_OLD_POSITION_INFO)), SessionPositionInfo.DEFAULT_POSITION_INFO);
    PositionInfo newPositionInfo = BundleableUtil.fromNullableBundle(PositionInfo.CREATOR, bundle.getBundle(keyForField(FIELD_NEW_POSITION_INFO)), SessionPositionInfo.DEFAULT_POSITION_INFO);
    int discontinuityReason = bundle.getInt(keyForField(FIELD_DISCONTINUITY_REASON), DISCONTINUITY_REASON_AUTO_TRANSITION);
    @Nullable Bundle playbackParametersBundle = bundle.getBundle(keyForField(FIELD_PLAYBACK_PARAMETERS));
    PlaybackParameters playbackParameters = BundleableUtil.fromNullableBundle(PlaybackParameters.CREATOR, playbackParametersBundle, /* defaultValue= */
    PlaybackParameters.DEFAULT);
    @Player.RepeatMode int repeatMode = bundle.getInt(keyForField(FIELD_REPEAT_MODE), /* defaultValue= */
    Player.REPEAT_MODE_OFF);
    boolean shuffleModeEnabled = bundle.getBoolean(keyForField(FIELD_SHUFFLE_MODE_ENABLED), /* defaultValue= */
    false);
    Timeline timeline = BundleableUtil.fromNullableBundle(Timeline.CREATOR, bundle.getBundle(keyForField(FIELD_TIMELINE)), Timeline.EMPTY);
    VideoSize videoSize = BundleableUtil.fromNullableBundle(VideoSize.CREATOR, bundle.getBundle(keyForField(FIELD_VIDEO_SIZE)), VideoSize.UNKNOWN);
    MediaMetadata playlistMetadata = BundleableUtil.fromNullableBundle(MediaMetadata.CREATOR, bundle.getBundle(keyForField(FIELD_PLAYLIST_METADATA)), MediaMetadata.EMPTY);
    float volume = bundle.getFloat(keyForField(FIELD_VOLUME), /* defaultValue= */
    1);
    AudioAttributes audioAttributes = BundleableUtil.fromNullableBundle(AudioAttributes.CREATOR, bundle.getBundle(keyForField(FIELD_AUDIO_ATTRIBUTES)), /* defaultValue= */
    AudioAttributes.DEFAULT);
    List<Cue> cues = BundleableUtil.fromBundleNullableList(Cue.CREATOR, bundle.getParcelableArrayList(keyForField(FIELD_CUES)), /* defaultValue= */
    ImmutableList.of());
    @Nullable Bundle deviceInfoBundle = bundle.getBundle(keyForField(FIELD_DEVICE_INFO));
    DeviceInfo deviceInfo = BundleableUtil.fromNullableBundle(DeviceInfo.CREATOR, deviceInfoBundle, /* defaultValue= */
    DeviceInfo.UNKNOWN);
    int deviceVolume = bundle.getInt(keyForField(FIELD_DEVICE_VOLUME), /* defaultValue= */
    0);
    boolean deviceMuted = bundle.getBoolean(keyForField(FIELD_DEVICE_MUTED), /* defaultValue= */
    false);
    boolean playWhenReady = bundle.getBoolean(keyForField(FIELD_PLAY_WHEN_READY), /* defaultValue= */
    false);
    int playWhenReadyChangedReason = bundle.getInt(keyForField(FIELD_PLAY_WHEN_READY_CHANGED_REASON), /* defaultValue= */
    PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST);
    @Player.PlaybackSuppressionReason int playbackSuppressionReason = bundle.getInt(keyForField(FIELD_PLAYBACK_SUPPRESSION_REASON), /* defaultValue= */
    PLAYBACK_SUPPRESSION_REASON_NONE);
    @Player.State int playbackState = bundle.getInt(keyForField(FIELD_PLAYBACK_STATE), /* defaultValue= */
    STATE_IDLE);
    boolean isPlaying = bundle.getBoolean(keyForField(FIELD_IS_PLAYING), /* defaultValue= */
    false);
    boolean isLoading = bundle.getBoolean(keyForField(FIELD_IS_LOADING), /* defaultValue= */
    false);
    MediaMetadata mediaMetadata = BundleableUtil.fromNullableBundle(MediaMetadata.CREATOR, bundle.getBundle(keyForField(FIELD_MEDIA_METADATA)), MediaMetadata.EMPTY);
    long seekBackIncrementMs = bundle.getLong(keyForField(FIELD_SEEK_BACK_INCREMENT_MS), /* defaultValue= */
    0);
    long seekForwardIncrementMs = bundle.getLong(keyForField(FIELD_SEEK_FORWARD_INCREMENT_MS), /* defaultValue= */
    0);
    long maxSeekToPreviousPosition = bundle.getLong(keyForField(FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS), /* defaultValue= */
    0);
    TrackSelectionParameters trackSelectionParameters = BundleableUtil.fromNullableBundle(TrackSelectionParameters.CREATOR, bundle.getBundle(keyForField(FIELD_TRACK_SELECTION_PARAMETERS)), TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT);
    return new PlayerInfo(playerError, mediaItemTransitionReason, sessionPositionInfo, oldPositionInfo, newPositionInfo, discontinuityReason, playbackParameters, repeatMode, shuffleModeEnabled, videoSize, timeline, playlistMetadata, volume, audioAttributes, cues, deviceInfo, deviceVolume, deviceMuted, playWhenReady, playWhenReadyChangedReason, playbackSuppressionReason, playbackState, isPlaying, isLoading, mediaMetadata, seekBackIncrementMs, seekForwardIncrementMs, maxSeekToPreviousPosition, trackSelectionParameters);
}
Also used : PlaybackException(androidx.media3.common.PlaybackException) PlaybackSuppressionReason(androidx.media3.common.Player.PlaybackSuppressionReason) Bundle(android.os.Bundle) AudioAttributes(androidx.media3.common.AudioAttributes) State(androidx.media3.common.Player.State) Timeline(androidx.media3.common.Timeline) Cue(androidx.media3.common.text.Cue) TrackSelectionParameters(androidx.media3.common.TrackSelectionParameters) VideoSize(androidx.media3.common.VideoSize) DeviceInfo(androidx.media3.common.DeviceInfo) PositionInfo(androidx.media3.common.Player.PositionInfo) MediaMetadata(androidx.media3.common.MediaMetadata) Nullable(androidx.annotation.Nullable) PlaybackParameters(androidx.media3.common.PlaybackParameters)

Example 4 with RepeatMode

use of androidx.media3.common.Player.RepeatMode in project media by androidx.

the class MediaControllerImplLegacy method buildNewControllerInfo.

private static ControllerInfo buildNewControllerInfo(boolean initialUpdate, LegacyPlayerInfo oldLegacyPlayerInfo, ControllerInfo oldControllerInfo, LegacyPlayerInfo newLegacyPlayerInfo, long sessionFlags, boolean isSessionReady, @RatingCompat.Style int ratingType, long timeDiffMs) {
    QueueTimeline currentTimeline;
    MediaMetadata mediaMetadata;
    int currentMediaItemIndex;
    MediaMetadata playlistMetadata;
    @RepeatMode int repeatMode;
    boolean shuffleModeEnabled;
    SessionCommands availableSessionCommands;
    Commands availablePlayerCommands;
    ImmutableList<CommandButton> customLayout;
    boolean isQueueChanged = oldLegacyPlayerInfo.queue != newLegacyPlayerInfo.queue;
    currentTimeline = isQueueChanged ? QueueTimeline.create(newLegacyPlayerInfo.queue) : new QueueTimeline((QueueTimeline) oldControllerInfo.playerInfo.timeline);
    boolean isMetadataCompatChanged = oldLegacyPlayerInfo.mediaMetadataCompat != newLegacyPlayerInfo.mediaMetadataCompat || initialUpdate;
    long oldActiveQueueId = getActiveQueueId(oldLegacyPlayerInfo.playbackStateCompat);
    long newActiveQueueId = getActiveQueueId(newLegacyPlayerInfo.playbackStateCompat);
    boolean isCurrentActiveQueueIdChanged = (oldActiveQueueId != newActiveQueueId) || initialUpdate;
    if (isMetadataCompatChanged || isCurrentActiveQueueIdChanged || isQueueChanged) {
        currentMediaItemIndex = findQueueItemIndex(newLegacyPlayerInfo.queue, newActiveQueueId);
        boolean hasMediaMetadataCompat = newLegacyPlayerInfo.mediaMetadataCompat != null;
        if (hasMediaMetadataCompat && isMetadataCompatChanged) {
            mediaMetadata = MediaUtils.convertToMediaMetadata(newLegacyPlayerInfo.mediaMetadataCompat, ratingType);
        } else if (!hasMediaMetadataCompat && isCurrentActiveQueueIdChanged) {
            mediaMetadata = (currentMediaItemIndex == C.INDEX_UNSET) ? MediaMetadata.EMPTY : MediaUtils.convertToMediaMetadata(newLegacyPlayerInfo.queue.get(currentMediaItemIndex).getDescription(), ratingType);
        } else {
            mediaMetadata = oldControllerInfo.playerInfo.mediaMetadata;
        }
        if (currentMediaItemIndex == C.INDEX_UNSET && isMetadataCompatChanged) {
            if (hasMediaMetadataCompat) {
                Log.w(TAG, "Adding a fake MediaItem at the end of the list because there's no QueueItem with" + " the active queue id and current Timeline should have currently playing" + " MediaItem.");
                MediaItem fakeMediaItem = MediaUtils.convertToMediaItem(newLegacyPlayerInfo.mediaMetadataCompat, ratingType);
                currentTimeline = currentTimeline.copyWithFakeMediaItem(fakeMediaItem);
                currentMediaItemIndex = currentTimeline.getWindowCount() - 1;
            } else {
                currentTimeline = currentTimeline.copyWithFakeMediaItem(/* fakeMediaItem= */
                null);
                // Shouldn't be C.INDEX_UNSET to make getCurrentMediaItemIndex() return masked index.
                // In other words, this index is either the currently playing media item index or the
                // would-be playing index when playing.
                currentMediaItemIndex = 0;
            }
        } else if (currentMediaItemIndex != C.INDEX_UNSET) {
            currentTimeline = currentTimeline.copyWithFakeMediaItem(/* fakeMediaItem= */
            null);
            if (hasMediaMetadataCompat) {
                MediaItem mediaItem = MediaUtils.convertToMediaItem(currentTimeline.getMediaItemAt(currentMediaItemIndex).mediaId, newLegacyPlayerInfo.mediaMetadataCompat, ratingType);
                currentTimeline = currentTimeline.copyWithNewMediaItem(/* replaceIndex= */
                currentMediaItemIndex, mediaItem);
            }
        } else {
            // There's queue, but no valid queue item ID nor current media item metadata.
            // Fallback to use 0 as current media item index to mask current item index.
            currentMediaItemIndex = 0;
        }
    } else {
        currentMediaItemIndex = oldControllerInfo.playerInfo.sessionPositionInfo.positionInfo.mediaItemIndex;
        mediaMetadata = oldControllerInfo.playerInfo.mediaMetadata;
    }
    playlistMetadata = oldLegacyPlayerInfo.queueTitle == newLegacyPlayerInfo.queueTitle ? oldControllerInfo.playerInfo.playlistMetadata : MediaUtils.convertToMediaMetadata(newLegacyPlayerInfo.queueTitle);
    repeatMode = MediaUtils.convertToRepeatMode(newLegacyPlayerInfo.repeatMode);
    shuffleModeEnabled = MediaUtils.convertToShuffleModeEnabled(newLegacyPlayerInfo.shuffleMode);
    if (oldLegacyPlayerInfo.playbackStateCompat != newLegacyPlayerInfo.playbackStateCompat) {
        availableSessionCommands = MediaUtils.convertToSessionCommands(newLegacyPlayerInfo.playbackStateCompat, isSessionReady);
        customLayout = MediaUtils.convertToCustomLayout(newLegacyPlayerInfo.playbackStateCompat);
    } else {
        availableSessionCommands = oldControllerInfo.availableSessionCommands;
        customLayout = oldControllerInfo.customLayout;
    }
    // Note: Sets the available player command here although it can be obtained before session is
    // ready. It's to follow the decision on MediaController to disallow any commands before
    // connection is made.
    availablePlayerCommands = (oldControllerInfo.availablePlayerCommands == Commands.EMPTY) ? MediaUtils.convertToPlayerCommands(sessionFlags, isSessionReady) : oldControllerInfo.availablePlayerCommands;
    PlaybackException playerError = MediaUtils.convertToPlaybackException(newLegacyPlayerInfo.playbackStateCompat);
    long durationMs = MediaUtils.convertToDurationMs(newLegacyPlayerInfo.mediaMetadataCompat);
    long currentPositionMs = MediaUtils.convertToCurrentPositionMs(newLegacyPlayerInfo.playbackStateCompat, newLegacyPlayerInfo.mediaMetadataCompat, timeDiffMs);
    long bufferedPositionMs = MediaUtils.convertToBufferedPositionMs(newLegacyPlayerInfo.playbackStateCompat, newLegacyPlayerInfo.mediaMetadataCompat, timeDiffMs);
    int bufferedPercentage = MediaUtils.convertToBufferedPercentage(newLegacyPlayerInfo.playbackStateCompat, newLegacyPlayerInfo.mediaMetadataCompat, timeDiffMs);
    long totalBufferedDurationMs = MediaUtils.convertToTotalBufferedDurationMs(newLegacyPlayerInfo.playbackStateCompat, newLegacyPlayerInfo.mediaMetadataCompat, timeDiffMs);
    boolean isPlayingAd = MediaUtils.convertToIsPlayingAd(newLegacyPlayerInfo.mediaMetadataCompat);
    PlaybackParameters playbackParameters = MediaUtils.convertToPlaybackParameters(newLegacyPlayerInfo.playbackStateCompat);
    AudioAttributes audioAttributes = MediaUtils.convertToAudioAttributes(newLegacyPlayerInfo.playbackInfoCompat);
    boolean playWhenReady = MediaUtils.convertToPlayWhenReady(newLegacyPlayerInfo.playbackStateCompat);
    @State int playbackState = MediaUtils.convertToPlaybackState(newLegacyPlayerInfo.playbackStateCompat, newLegacyPlayerInfo.mediaMetadataCompat, timeDiffMs);
    boolean isPlaying = MediaUtils.convertToIsPlaying(newLegacyPlayerInfo.playbackStateCompat);
    DeviceInfo deviceInfo = MediaUtils.convertToDeviceInfo(newLegacyPlayerInfo.playbackInfoCompat);
    int deviceVolume = MediaUtils.convertToDeviceVolume(newLegacyPlayerInfo.playbackInfoCompat);
    boolean deviceMuted = MediaUtils.convertToIsDeviceMuted(newLegacyPlayerInfo.playbackInfoCompat);
    long seekBackIncrementMs = oldControllerInfo.playerInfo.seekBackIncrementMs;
    long seekForwardIncrementMs = oldControllerInfo.playerInfo.seekForwardIncrementMs;
    return createControllerInfo(currentTimeline, mediaMetadata, currentMediaItemIndex, playlistMetadata, repeatMode, shuffleModeEnabled, availableSessionCommands, availablePlayerCommands, customLayout, playerError, durationMs, currentPositionMs, bufferedPositionMs, bufferedPercentage, totalBufferedDurationMs, isPlayingAd, playbackParameters, audioAttributes, playWhenReady, playbackState, isPlaying, deviceInfo, deviceVolume, deviceMuted, seekBackIncrementMs, seekForwardIncrementMs);
}
Also used : PlaybackException(androidx.media3.common.PlaybackException) AudioAttributes(androidx.media3.common.AudioAttributes) RepeatMode(androidx.media3.common.Player.RepeatMode) MediaItem(androidx.media3.common.MediaItem) State(androidx.media3.common.Player.State) Commands(androidx.media3.common.Player.Commands) DeviceInfo(androidx.media3.common.DeviceInfo) MediaMetadata(androidx.media3.common.MediaMetadata) PlaybackParameters(androidx.media3.common.PlaybackParameters)

Example 5 with RepeatMode

use of androidx.media3.common.Player.RepeatMode in project media by androidx.

the class MediaControllerImplLegacy method createControllerInfo.

private static ControllerInfo createControllerInfo(QueueTimeline currentTimeline, MediaMetadata mediaMetadata, int currentMediaItemIndex, MediaMetadata playlistMetadata, @RepeatMode int repeatMode, boolean shuffleModeEnabled, SessionCommands availableSessionCommands, Commands availablePlayerCommands, ImmutableList<CommandButton> customLayout, @Nullable PlaybackException playerError, long durationMs, long currentPositionMs, long bufferedPositionMs, int bufferedPercentage, long totalBufferedDurationMs, boolean isPlayingAd, PlaybackParameters playbackParameters, AudioAttributes audioAttributes, boolean playWhenReady, int playbackState, boolean isPlaying, DeviceInfo deviceInfo, int deviceVolume, boolean deviceMuted, long seekBackIncrementMs, long seekForwardIncrementMs) {
    @Nullable MediaItem currentMediaItem = currentTimeline.getMediaItemAt(currentMediaItemIndex);
    PositionInfo positionInfo = createPositionInfo(currentMediaItemIndex, currentMediaItem, currentPositionMs);
    SessionPositionInfo sessionPositionInfo = new SessionPositionInfo(/* positionInfo= */
    positionInfo, /* isPlayingAd= */
    isPlayingAd, /* eventTimeMs= */
    C.TIME_UNSET, /* durationMs= */
    durationMs, /* bufferedPositionMs= */
    bufferedPositionMs, /* bufferedPercentage= */
    bufferedPercentage, /* totalBufferedDurationMs= */
    totalBufferedDurationMs, /* currentLiveOffsetMs= */
    C.TIME_UNSET, /* contentDurationMs= */
    durationMs, /* contentBufferedPositionMs= */
    bufferedPositionMs);
    PlayerInfo playerInfo = new PlayerInfo(/* playerError= */
    playerError, /* mediaItemTransitionReason= */
    PlayerInfo.MEDIA_ITEM_TRANSITION_REASON_DEFAULT, /* sessionPositionInfo= */
    sessionPositionInfo, /* oldPositionInfo= */
    SessionPositionInfo.DEFAULT_POSITION_INFO, /* newPositionInfo= */
    SessionPositionInfo.DEFAULT_POSITION_INFO, /* discontinuityReason= */
    PlayerInfo.DISCONTINUITY_REASON_DEFAULT, /* playbackParameters= */
    playbackParameters, /* repeatMode= */
    repeatMode, /* shuffleModeEnabled= */
    shuffleModeEnabled, /* videoSize= */
    VideoSize.UNKNOWN, /* timeline= */
    currentTimeline, /* playlistMetadata= */
    playlistMetadata, /* volume= */
    1.0f, /* audioAttributes= */
    audioAttributes, /* cues= */
    Collections.emptyList(), /* deviceInfo= */
    deviceInfo, /* deviceVolume= */
    deviceVolume, /* deviceMuted= */
    deviceMuted, /* playWhenReady= */
    playWhenReady, /* playWhenReadyChangedReason= */
    PlayerInfo.PLAY_WHEN_READY_CHANGE_REASON_DEFAULT, /* playbackSuppressionReason= */
    Player.PLAYBACK_SUPPRESSION_REASON_NONE, /* playbackState= */
    playbackState, /* isPlaying= */
    isPlaying, /* isLoading= */
    false, /* mediaMetadata= */
    mediaMetadata, seekBackIncrementMs, seekForwardIncrementMs, /* maxSeekToPreviousPositionMs= */
    0L, /* parameters= */
    TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT);
    return new ControllerInfo(playerInfo, availableSessionCommands, availablePlayerCommands, customLayout);
}
Also used : MediaItem(androidx.media3.common.MediaItem) PositionInfo(androidx.media3.common.Player.PositionInfo) Nullable(androidx.annotation.Nullable)

Aggregations

Test (org.junit.Test)14 LargeTest (androidx.test.filters.LargeTest)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 RepeatMode (androidx.media3.common.Player.RepeatMode)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 Player (androidx.media3.common.Player)9 Timeline (androidx.media3.common.Timeline)9 Nullable (androidx.annotation.Nullable)7 MediaMetadata (androidx.media3.common.MediaMetadata)7 Bundle (android.os.Bundle)6 MediaItem (androidx.media3.common.MediaItem)6 PlaybackParameters (androidx.media3.common.PlaybackParameters)6 FlagSet (androidx.media3.common.FlagSet)5 State (androidx.media3.common.Player.State)5 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)4 RemoteMockPlayer (androidx.media3.session.RemoteMediaSession.RemoteMockPlayer)4 AudioAttributes (androidx.media3.common.AudioAttributes)3 PositionInfo (androidx.media3.common.Player.PositionInfo)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3