Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

belongs to Maven artifact androidx.media2:media2:1.0.0-alpha02

MediaSession2.Builder

public static final class MediaSession2.Builder
extends Object

java.lang.Object
   ↳ androidx.media2.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(BaseMediaPlayer player)

Sets the underlying BaseMediaPlayer 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 BaseMediaPlayer.

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.

Inherited methods

Public constructors

MediaSession2.Builder

public MediaSession2.Builder (Context context)

Parameters
context Context

Public methods

build

public MediaSession2 build ()

Build MediaSession2.

Returns
MediaSession2 a new session

setId

public 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

public MediaSession2.Builder setPlayer (BaseMediaPlayer player)

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

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

Returns
MediaSession2.Builder

setPlaylistAgent

public MediaSession2.Builder setPlaylistAgent (MediaPlaylistAgent playlistAgent)

Sets the MediaPlaylistAgent for this session to manages playlist of the underlying BaseMediaPlayer. The playlist agent should manage BaseMediaPlayer for calling BaseMediaPlayer.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

public 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

public 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