public final class

MediaSession.Builder

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

 java.lang.Object

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

↳androidx.media3.session.MediaSession.Builder

Overview

A builder for MediaSession.

Any incoming requests from the MediaController will be handled on the application thread of the underlying Player.

Summary

Constructors
publicBuilder(Context context, Player player)

Creates a builder for MediaSession.

Methods
public MediaSessionbuild()

Builds a MediaSession.

public MediaSession.BuildersetExtras(Bundle extras)

Sets an extra for the MediaSession.

public MediaSession.BuildersetId(java.lang.String id)

Sets an ID of the MediaSession.

public MediaSession.BuildersetMediaItemFiller(MediaSession.MediaItemFiller mediaItemFiller)

Sets the logic used to fill in the fields of a MediaItem from MediaController.

public MediaSession.BuildersetSessionActivity(PendingIntent pendingIntent)

Sets a PendingIntent to launch an for the MediaSession.

public MediaSession.BuildersetSessionCallback(MediaSession.SessionCallback callback)

Sets a callback for the MediaSession to handle incoming requests from {link MediaController}.

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

Constructors

public Builder(Context context, Player player)

Creates a builder for MediaSession.

Parameters:

context: The context.
player: The underlying player to perform playback and handle transport controls.

Methods

public MediaSession.Builder setSessionActivity(PendingIntent pendingIntent)

Sets a PendingIntent to launch an for the MediaSession. This can be used as a quick link to an ongoing media screen.

Parameters:

pendingIntent: The pending intent.

Returns:

The builder to allow chaining.

public MediaSession.Builder setId(java.lang.String id)

Sets an ID of the MediaSession. If not set, an empty string will be used.

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-grained controls.

Parameters:

id: The ID. Must be unique among all sessions per package.

Returns:

The builder to allow chaining.

public MediaSession.Builder setSessionCallback(MediaSession.SessionCallback callback)

Sets a callback for the MediaSession to handle incoming requests from {link MediaController}.

Parameters:

callback: The callback.

Returns:

The builder to allow chaining.

public MediaSession.Builder setMediaItemFiller(MediaSession.MediaItemFiller mediaItemFiller)

Sets the logic used to fill in the fields of a MediaItem from MediaController.

Parameters:

mediaItemFiller: The filler.

Returns:

The builder to allow chaining.

public MediaSession.Builder setExtras(Bundle extras)

Sets an extra for the MediaSession. The MediaSession.getToken() session token} will have the extras. If not set, an empty will be used.

Parameters:

extras: The extra .

Returns:

The builder to allow chaining.

public MediaSession build()

Builds a MediaSession.

Returns:

A new session.