Stay organized with collections Save and categorize content based on your preferences.

MediaSession.Builder

public final class MediaSession.Builder


A builder for MediaSession.

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

Summary

Public constructors

Builder(Context context, Player player)

Creates a builder for MediaSession.

Public methods

MediaSession

Builds a MediaSession.

MediaSession.Builder

Sets a BitmapLoader for the MediaSession to decode bitmaps from compressed binary data or load bitmaps from Uri.

MediaSession.Builder

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

MediaSession.Builder
setExtras(Bundle extras)

Sets an extra Bundle for the MediaSession.

MediaSession.Builder

Sets an ID of the MediaSession.

MediaSession.Builder

Sets a PendingIntent to launch an android.app.Activity for the .

Public constructors

Builder

public Builder(Context context, Player player)

Creates a builder for MediaSession.

Parameters
Context context

The context.

Player player

The underlying player to perform playback and handle transport controls.

Throws
java.lang.IllegalArgumentException java.lang.IllegalArgumentException

if canAdvertiseSession returns false.

Public methods

build

public MediaSession build()

Builds a MediaSession.

Returns
MediaSession

A new session.

Throws
java.lang.IllegalStateException java.lang.IllegalStateException

if a MediaSession with the same ID already exists in the package.

setBitmapLoader

@UnstableApi
public MediaSession.Builder setBitmapLoader(BitmapLoader bitmapLoader)

Sets a BitmapLoader for the MediaSession to decode bitmaps from compressed binary data or load bitmaps from Uri. If not set, a CacheBitmapLoader with a SimpleBitmapLoader inside will be used.

The provided instance will likely be called repeatedly with the same request, so it would be best if any provided instance does some caching. Simple caching can be added to any implementation by wrapping it in CacheBitmapLoader before passing it to this method.

If no instance is set, a CacheBitmapLoader with a SimpleBitmapLoader inside will be used.

Parameters
BitmapLoader bitmapLoader

The bitmap loader BitmapLoader.

Returns
MediaSession.Builder

The builder to allow chaining.

setCallback

public MediaSession.Builder setCallback(MediaSession.Callback callback)

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

Parameters
MediaSession.Callback callback

The callback.

Returns
MediaSession.Builder

The builder to allow chaining.

setExtras

public MediaSession.Builder setExtras(Bundle extras)

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

Parameters
Bundle extras

The extra Bundle.

Returns
MediaSession.Builder

The builder to allow chaining.

setId

public MediaSession.Builder setId(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
String id

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

Returns
MediaSession.Builder

The builder to allow chaining.

setSessionActivity

public MediaSession.Builder setSessionActivity(PendingIntent pendingIntent)

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

A client can use this pending intent to start an activity belonging to this session. When this pending intent is for instance included in the notification as the content intent, tapping the notification will open this activity.

See 'Start an Activity from a Notification' also.

Parameters
PendingIntent pendingIntent

The pending intent.

Returns
MediaSession.Builder

The builder to allow chaining.