public final class

MediaSession.Builder

extends androidx.media2.session.MediaSession.BuilderBase<MediaSession, MediaSession.Builder, MediaSession.SessionCallback>

 java.lang.Object

↳androidx.media2.session.MediaSession.BuilderBase<MediaSession, MediaSession.Builder, MediaSession.SessionCallback>

↳androidx.media2.session.MediaSession.Builder

Overview

Builder for MediaSession.

Any incoming event from the MediaController will be handled on the callback executor. If it's not set, ContextCompat.getMainExecutor(Context) will be used by default.

Summary

Constructors
publicBuilder(Context context, SessionPlayer player)

Methods
abstract MediaSessionbuild()

Builds a MediaSession.

androidx.media2.session.MediaSession.BuilderBase<T, U, C>setExtras(Bundle extras)

Sets extras for the session token.

androidx.media2.session.MediaSession.BuilderBase<T, U, C>setId(java.lang.String id)

Sets the ID of the session.

androidx.media2.session.MediaSession.BuilderBase<T, U, C>setSessionActivity(PendingIntent pi)

Sets an intent for launching UI for this Session.

androidx.media2.session.MediaSession.BuilderBase<T, U, C>setSessionCallback(java.util.concurrent.Executor executor, MediaSession.SessionCallback callback)

Sets callback for the session.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(Context context, SessionPlayer player)

Methods

androidx.media2.session.MediaSession.BuilderBase<T, U, C> setSessionActivity(PendingIntent pi)

Sets 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 .

Parameters:

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

androidx.media2.session.MediaSession.BuilderBase<T, U, C> setId(java.lang.String id)

Sets the ID of the session. If it's not set, an empty string will be 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: id of the session. Must be unique per package.

Returns:

androidx.media2.session.MediaSession.BuilderBase<T, U, C> setSessionCallback(java.util.concurrent.Executor executor, MediaSession.SessionCallback callback)

Sets callback for the session.

Parameters:

executor: callback executor
callback: session callback

Returns:

androidx.media2.session.MediaSession.BuilderBase<T, U, C> setExtras(Bundle extras)

Sets extras for the session token. If not set, SessionToken.getExtras() will return an empty .

Returns:

the Builder to allow chaining

See also: SessionToken.getExtras()

abstract MediaSession build()

Builds a MediaSession.

Returns:

a new session