MediaSession.Builder

Added in 1.0.0
Deprecated in 1.3.0

public final class MediaSession.Builder


Builder for MediaSession.

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

Summary

Public constructors

Public methods

@NonNull MediaSession

Builds a MediaSession.

@NonNull MediaSession.Builder

Sets extras for the session token.

@NonNull MediaSession.Builder

Sets the ID of the session.

@NonNull MediaSession.Builder

Sets an intent for launching UI for this Session.

@NonNull MediaSession.Builder

Sets callback for the session.

Public constructors

Builder

Added in 1.0.0
Deprecated in 1.3.0
public Builder(@NonNull Context context, @NonNull SessionPlayer player)

Public methods

build

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull MediaSession build()

Builds a MediaSession.

Returns
@NonNull MediaSession

a new session

Throws
java.lang.IllegalStateException

if the session with the same id already exists for the package.

setExtras

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull MediaSession.Builder setExtras(@NonNull Bundle extras)

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

Returns
@NonNull MediaSession.Builder

the Builder to allow chaining

Throws
java.lang.IllegalArgumentException

if the bundle contains any non-framework Parcelable objects.

See also
getExtras

setId

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull MediaSession.Builder setId(@NonNull 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
@NonNull String id

id of the session. Must be unique per package.

setSessionActivity

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull MediaSession.Builder setSessionActivity(@Nullable 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 startActivity.

Parameters
@Nullable PendingIntent pi

The intent to launch to show UI for this session.

setSessionCallback

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull MediaSession.Builder setSessionCallback(
    @NonNull Executor executor,
    @NonNull MediaSession.SessionCallback callback
)

Sets callback for the session.

Parameters
@NonNull Executor executor

callback executor

@NonNull MediaSession.SessionCallback callback

session callback