belongs to Maven artifact androidx.media:media:1.0.0-alpha1

MediaSession2.Builder

public static final class MediaSession2.Builder
extends Object

java.lang.Object
   ↳ androidx.media.MediaSession2.Builder


Builder for MediaSession2.

Any incoming event from the MediaController2 will be handled on the thread that created session with the build().

Summary

Public constructors

MediaSession2.Builder(Context context)

Public methods

MediaSession2 build()

Build MediaSession2.

MediaSession2.Builder setId(String id)

Set ID of the session.

MediaSession2.Builder setPlayer(MediaPlayerInterface player)

Sets the underlying MediaPlayerInterface for this session to dispatch incoming event to.

MediaSession2.Builder setPlaylistAgent(MediaPlaylistAgent playlistAgent)

Sets the MediaPlaylistAgent for this session to manages playlist of the underlying MediaPlayerInterface.

MediaSession2.Builder setSessionActivity(PendingIntent pi)

Set an intent for launching UI for this Session.

MediaSession2.Builder setSessionCallback(Executor executor, MediaSession2.SessionCallback callback)

Set callback for the session.

MediaSession2.Builder setVolumeProvider(VolumeProviderCompat volumeProvider)

Sets the VolumeProviderCompat for this session to handle volume events.

Inherited methods

Public constructors

MediaSession2.Builder

MediaSession2.Builder (Context context)

Parameters
context Context

Public methods

build

MediaSession2 build ()

Build MediaSession2.

Returns
MediaSession2 a new session

setId

MediaSession2.Builder setId (String id)

Set ID of the session. If it's not set, an empty string with used to create a session.

Use this if and only if your app supports multiple playback at the same time and also wants to provide external apps to have finer controls of them.

Parameters
id String: id of the session. Must be unique per package.

Returns
MediaSession2.Builder

setPlayer

MediaSession2.Builder setPlayer (MediaPlayerInterface player)

Sets the underlying MediaPlayerInterface for this session to dispatch incoming event to.

Parameters
player MediaPlayerInterface: a MediaPlayerInterface that handles actual media playback in your app.

Returns
MediaSession2.Builder

setPlaylistAgent

MediaSession2.Builder setPlaylistAgent (MediaPlaylistAgent playlistAgent)

Sets the MediaPlaylistAgent for this session to manages playlist of the underlying MediaPlayerInterface. The playlist agent should manage MediaPlayerInterface for calling MediaPlayerInterface.setNextDataSources(List).

If the MediaPlaylistAgent isn't set, session will create the default playlist agent.

Parameters
playlistAgent MediaPlaylistAgent: a MediaPlaylistAgent that manages playlist of the player

Returns
MediaSession2.Builder

setSessionActivity

MediaSession2.Builder setSessionActivity (PendingIntent pi)

Set an intent for launching UI for this Session. This can be used as a quick link to an ongoing media screen. The intent should be for an activity that may be started using Context.startActivity(Intent).

Parameters
pi PendingIntent: The intent to launch to show UI for this session.

Returns
MediaSession2.Builder

setSessionCallback

MediaSession2.Builder setSessionCallback (Executor executor, 
                MediaSession2.SessionCallback callback)

Set callback for the session.

Parameters
executor Executor: callback executor

callback MediaSession2.SessionCallback: session callback.

Returns
MediaSession2.Builder

setVolumeProvider

MediaSession2.Builder setVolumeProvider (VolumeProviderCompat volumeProvider)

Sets the VolumeProviderCompat for this session to handle volume events. If not set, system will adjust the appropriate stream volume for this session's player.

Parameters
volumeProvider VolumeProviderCompat: The provider that will receive volume button events.

Returns
MediaSession2.Builder