Builder
Stay organized with collections
Save and categorize content based on your preferences.
class Builder
This API is not generally intended for third party application developers. Use the AndroidX Media3 session Library for consistent behavior across all devices.
Builder for MediaSession2
.
Any incoming event from the MediaController2
will be handled on the callback executor. If it's not set, Context.getMainExecutor()
will be used by default.
Summary
Public constructors | |
---|---|
Creates a builder for |
Public methods | |
---|---|
MediaSession2 |
build() Build |
MediaSession2.Builder |
Set extras for the session token. |
MediaSession2.Builder |
Set ID of the session. |
MediaSession2.Builder |
Set an intent for launching UI for this Session. |
MediaSession2.Builder |
setSessionCallback(executor: Executor, callback: MediaSession2.SessionCallback) Set callback for the session and its executor. |
Public constructors
Builder
Builder(context: Context)
Creates a builder for MediaSession2
.
Parameters | |
---|---|
context |
Context: Context This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if context is null . |
Public methods
build
fun build(): MediaSession2
Build MediaSession2
.
Return | |
---|---|
MediaSession2 |
a new session This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if the session with the same id is already exists for the package. |
setExtras
fun setExtras(extras: Bundle): MediaSession2.Builder
Set extras for the session token. If null or not set, Session2Token.getExtras()
will return an empty Bundle
. An IllegalArgumentException
will be thrown if the bundle contains any non-framework Parcelable objects.
Parameters | |
---|---|
extras |
Bundle: This value cannot be null . |
Return | |
---|---|
MediaSession2.Builder |
The Builder to allow chaining |
setId
fun setId(id: String): MediaSession2.Builder
Set 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 |
String: id of the session. Must be unique per package. This value cannot be null . |
Return | |
---|---|
MediaSession2.Builder |
The Builder to allow chaining This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if id is null . |
setSessionActivity
fun setSessionActivity(pi: PendingIntent?): MediaSession2.Builder
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. This value may be null . |
Return | |
---|---|
MediaSession2.Builder |
The Builder to allow chaining This value cannot be null . |
setSessionCallback
fun setSessionCallback(
executor: Executor,
callback: MediaSession2.SessionCallback
): MediaSession2.Builder
Set callback for the session and its executor.
Parameters | |
---|---|
executor |
Executor: callback executor This value cannot be null . |
callback |
MediaSession2.SessionCallback: session callback. This value cannot be null . |
Return | |
---|---|
MediaSession2.Builder |
The Builder to allow chaining This value cannot be null . |