Class SessionPlayerConnector

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public final class SessionPlayerConnector
    extends androidx.media2.common.SessionPlayer
    An implementation of SessionPlayer that wraps a given ExoPlayer Player instance.

    Internally this implementation posts operations to and receives callbacks on the thread associated with Player.getApplicationLooper(), so it is important not to block this thread. In particular, when awaiting the result of an asynchronous session player operation, apps should generally use ListenableFuture.addListener(Runnable, Executor) to be notified of completion, rather than calling the blocking Future.get() method.

    • Method Detail

      • play

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> play()
        Specified by:
        play in class androidx.media2.common.SessionPlayer
      • pause

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> pause()
        Specified by:
        pause in class androidx.media2.common.SessionPlayer
      • prepare

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> prepare()
        Specified by:
        prepare in class androidx.media2.common.SessionPlayer
      • seekTo

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> seekTo​(long position)
        Specified by:
        seekTo in class androidx.media2.common.SessionPlayer
      • setPlaybackSpeed

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> setPlaybackSpeed​(float playbackSpeed)
        Specified by:
        setPlaybackSpeed in class androidx.media2.common.SessionPlayer
      • setAudioAttributes

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> setAudioAttributes​(androidx.media.AudioAttributesCompat attr)
        Specified by:
        setAudioAttributes in class androidx.media2.common.SessionPlayer
      • getPlayerState

        public int getPlayerState()
        Specified by:
        getPlayerState in class androidx.media2.common.SessionPlayer
      • getCurrentPosition

        public long getCurrentPosition()
        Specified by:
        getCurrentPosition in class androidx.media2.common.SessionPlayer
      • getDuration

        public long getDuration()
        Specified by:
        getDuration in class androidx.media2.common.SessionPlayer
      • getBufferedPosition

        public long getBufferedPosition()
        Specified by:
        getBufferedPosition in class androidx.media2.common.SessionPlayer
      • getBufferingState

        public int getBufferingState()
        Specified by:
        getBufferingState in class androidx.media2.common.SessionPlayer
      • getPlaybackSpeed

        public float getPlaybackSpeed()
        Specified by:
        getPlaybackSpeed in class androidx.media2.common.SessionPlayer
      • getAudioAttributes

        @Nullable
        public androidx.media.AudioAttributesCompat getAudioAttributes()
        Specified by:
        getAudioAttributes in class androidx.media2.common.SessionPlayer
      • setMediaItem

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> setMediaItem​(androidx.media2.common.MediaItem item)

        FileMediaItem and CallbackMediaItem are not supported.

        Specified by:
        setMediaItem in class androidx.media2.common.SessionPlayer
      • setPlaylist

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> setPlaylist​(List<androidx.media2.common.MediaItem> playlist,
                                                                                               @Nullable
                                                                                               androidx.media2.common.MediaMetadata metadata)

        FileMediaItem and CallbackMediaItem are not supported.

        Specified by:
        setPlaylist in class androidx.media2.common.SessionPlayer
      • addPlaylistItem

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> addPlaylistItem​(int index,
                                                                                                   androidx.media2.common.MediaItem item)

        FileMediaItem and CallbackMediaItem are not supported.

        Specified by:
        addPlaylistItem in class androidx.media2.common.SessionPlayer
      • removePlaylistItem

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> removePlaylistItem​(int index)
        Specified by:
        removePlaylistItem in class androidx.media2.common.SessionPlayer
      • replacePlaylistItem

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> replacePlaylistItem​(int index,
                                                                                                       androidx.media2.common.MediaItem item)

        FileMediaItem and CallbackMediaItem are not supported.

        Specified by:
        replacePlaylistItem in class androidx.media2.common.SessionPlayer
      • movePlaylistItem

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> movePlaylistItem​(int fromIndex,
                                                                                                    int toIndex)
        Overrides:
        movePlaylistItem in class androidx.media2.common.SessionPlayer
      • skipToPreviousPlaylistItem

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> skipToPreviousPlaylistItem()
        Specified by:
        skipToPreviousPlaylistItem in class androidx.media2.common.SessionPlayer
      • skipToNextPlaylistItem

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> skipToNextPlaylistItem()
        Specified by:
        skipToNextPlaylistItem in class androidx.media2.common.SessionPlayer
      • skipToPlaylistItem

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> skipToPlaylistItem​(int index)
        Specified by:
        skipToPlaylistItem in class androidx.media2.common.SessionPlayer
      • updatePlaylistMetadata

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> updatePlaylistMetadata​(@Nullable
                                                                                                          androidx.media2.common.MediaMetadata metadata)
        Specified by:
        updatePlaylistMetadata in class androidx.media2.common.SessionPlayer
      • setRepeatMode

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> setRepeatMode​(int repeatMode)
        Specified by:
        setRepeatMode in class androidx.media2.common.SessionPlayer
      • setShuffleMode

        public ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> setShuffleMode​(int shuffleMode)
        Specified by:
        setShuffleMode in class androidx.media2.common.SessionPlayer
      • getPlaylist

        @Nullable
        public List<androidx.media2.common.MediaItem> getPlaylist()
        Specified by:
        getPlaylist in class androidx.media2.common.SessionPlayer
      • getPlaylistMetadata

        @Nullable
        public androidx.media2.common.MediaMetadata getPlaylistMetadata()
        Specified by:
        getPlaylistMetadata in class androidx.media2.common.SessionPlayer
      • getRepeatMode

        public int getRepeatMode()
        Specified by:
        getRepeatMode in class androidx.media2.common.SessionPlayer
      • getShuffleMode

        public int getShuffleMode()
        Specified by:
        getShuffleMode in class androidx.media2.common.SessionPlayer
      • getCurrentMediaItem

        @Nullable
        public androidx.media2.common.MediaItem getCurrentMediaItem()
        Specified by:
        getCurrentMediaItem in class androidx.media2.common.SessionPlayer
      • getCurrentMediaItemIndex

        public int getCurrentMediaItemIndex()
        Specified by:
        getCurrentMediaItemIndex in class androidx.media2.common.SessionPlayer
      • getPreviousMediaItemIndex

        public int getPreviousMediaItemIndex()
        Specified by:
        getPreviousMediaItemIndex in class androidx.media2.common.SessionPlayer
      • getNextMediaItemIndex

        public int getNextMediaItemIndex()
        Specified by:
        getNextMediaItemIndex in class androidx.media2.common.SessionPlayer
      • close

        public void close()
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Overrides:
        close in class androidx.media2.common.SessionPlayer