Package com.google.android.exoplayer2.ext.media2

## Class SessionPlayerConnector

- java.lang.Object
- - androidx.media2.common.SessionPlayer
  - - com.google.android.exoplayer2.ext.media2.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.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class androidx.media2.common.SessionPlayer

      `androidx.media2.common.SessionPlayer.BuffState, androidx.media2.common.SessionPlayer.PlayerCallback, androidx.media2.common.SessionPlayer.PlayerResult, androidx.media2.common.SessionPlayer.PlayerState, androidx.media2.common.SessionPlayer.RepeatMode, androidx.media2.common.SessionPlayer.ShuffleMode, androidx.media2.common.SessionPlayer.TrackInfo`

  - ### Field Summary

    - ### Fields inherited from class androidx.media2.common.SessionPlayer

      `BUFFERING_STATE_BUFFERING_AND_PLAYABLE, BUFFERING_STATE_BUFFERING_AND_STARVED, BUFFERING_STATE_COMPLETE, BUFFERING_STATE_UNKNOWN, INVALID_ITEM_INDEX, PLAYER_STATE_ERROR, PLAYER_STATE_IDLE, PLAYER_STATE_PAUSED, PLAYER_STATE_PLAYING, REPEAT_MODE_ALL, REPEAT_MODE_GROUP, REPEAT_MODE_NONE, REPEAT_MODE_ONE, SHUFFLE_MODE_ALL, SHUFFLE_MODE_GROUP, SHUFFLE_MODE_NONE, UNKNOWN_TIME`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `SessionPlayerConnector​(Player player)` | Creates an instance using `DefaultMediaItemConverter` to convert between ExoPlayer and media2 MediaItems.
    `SessionPlayerConnector​(Player player, MediaItemConverter mediaItemConverter)` | Creates an instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `addPlaylistItem​(int index, androidx.media2.common.MediaItem item)`
    `void` | `close()` |
    `androidx.media.AudioAttributesCompat` | `getAudioAttributes()` |
    `long` | `getBufferedPosition()` |
    `int` | `getBufferingState()` |
    `androidx.media2.common.MediaItem` | `getCurrentMediaItem()` |
    `int` | `getCurrentMediaItemIndex()` |
    `long` | `getCurrentPosition()` |
    `long` | `getDuration()` |
    `int` | `getNextMediaItemIndex()` |
    `float` | `getPlaybackSpeed()` |
    `int` | `getPlayerState()` |
    `List<androidx.media2.common.MediaItem>` | `getPlaylist()` |
    `androidx.media2.common.MediaMetadata` | `getPlaylistMetadata()` |
    `int` | `getPreviousMediaItemIndex()` |
    `int` | `getRepeatMode()` |
    `int` | `getShuffleMode()` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `movePlaylistItem​(int fromIndex, int toIndex)` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `pause()` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `play()` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `prepare()` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `removePlaylistItem​(int index)` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `replacePlaylistItem​(int index, androidx.media2.common.MediaItem item)`
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `seekTo​(long position)` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `setAudioAttributes​(androidx.media.AudioAttributesCompat attr)` |
    `void` | `setControlDispatcher​(ControlDispatcher controlDispatcher)` | Deprecated. Use a `ForwardingPlayer` and pass it to the constructor instead.
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `setMediaItem​(androidx.media2.common.MediaItem item)`
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `setPlaybackSpeed​(float playbackSpeed)` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `setPlaylist​(List<androidx.media2.common.MediaItem> playlist, androidx.media2.common.MediaMetadata metadata)`
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `setRepeatMode​(int repeatMode)` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `setShuffleMode​(int shuffleMode)` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `skipToNextPlaylistItem()` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `skipToPlaylistItem​(int index)` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `skipToPreviousPlaylistItem()` |
    `ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult>` | `updatePlaylistMetadata​(androidx.media2.common.MediaMetadata metadata)` |

    - ### Methods inherited from class androidx.media2.common.SessionPlayer

      `deselectTrack, getCallbacks, getSelectedTrack, getTracks, getVideoSize, registerPlayerCallback, selectTrack, setSurface, unregisterPlayerCallback`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SessionPlayerConnector

          public SessionPlayerConnector​(Player player)

      Creates an instance using `DefaultMediaItemConverter` to convert between ExoPlayer and media2 MediaItems.
      Parameters:
        `player` - The player to wrap.

    - #### SessionPlayerConnector

          public SessionPlayerConnector​(Player player,
                                        MediaItemConverter mediaItemConverter)

      Creates an instance.
      Parameters:
        `player` - The player to wrap.
        `mediaItemConverter` - The `MediaItemConverter`.

  - ### Method Detail

    - #### setControlDispatcher

          @Deprecated
          public void setControlDispatcher​(ControlDispatcher controlDispatcher)

      Deprecated.
      Use a `ForwardingPlayer` and pass it to the constructor instead. You can also customize some operations when configuring the player (for example by using `SimpleExoPlayer.Builder#setSeekBackIncrementMs(long)`).

    - #### 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​(@FloatRange(from=0.0,to=3.4028234663852886E38,fromInclusive=false)
                                                                                                      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

          @FloatRange(from=0.0,
                      to=3.4028234663852886E38,
                      fromInclusive=false)
          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​(@IntRange(from=0L)
                                                                                                        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​(@IntRange(from=0L)
                                                                                                        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`