MediaController.Builder
public
static
final
class
MediaController.Builder
extends Object
java.lang.Object | |
↳ | androidx.media2.session.MediaController.Builder |
Builder for MediaController
.
To set the token of the session for the controller to connect to, one of the
setSessionToken(SessionToken)
or
setSessionCompatToken(MediaSessionCompat.Token)
should be called.
Otherwise, the build()
will throw an IllegalArgumentException
.
Any incoming event from the MediaSession
will be handled on the callback
executor.
Summary
Public constructors | |
---|---|
Builder(Context context)
|
Public methods | |
---|---|
MediaController
|
build()
Builds a |
MediaController.Builder
|
setConnectionHints(Bundle connectionHints)
Sets the connection hints for the controller. |
MediaController.Builder
|
setControllerCallback(Executor executor, MediaController.ControllerCallback callback)
Sets the callback for the controller and its executor. |
MediaController.Builder
|
setSessionCompatToken(MediaSessionCompat.Token compatToken)
Sets the |
MediaController.Builder
|
setSessionToken(SessionToken token)
Sets the |
Inherited methods | |
---|---|
Public constructors
Public methods
build
public MediaController build ()
Builds a MediaController
.
Returns | |
---|---|
MediaController |
a new controller |
Throws | |
---|---|
IllegalArgumentException |
if both SessionToken and
MediaSessionCompat.Token are not set. |
setConnectionHints
public MediaController.Builder setConnectionHints (Bundle connectionHints)
Sets the connection hints for the controller.
connectionHints
is a session-specific argument to send to the session when
connecting. The contents of this bundle may affect the connection result.
The hints specified here are only used when when connecting to the MediaSession
.
They will be ignored when connecting to MediaSessionCompat
.
Parameters | |
---|---|
connectionHints |
Bundle : a bundle which contains the connection hints |
Returns | |
---|---|
MediaController.Builder |
the Builder to allow chaining |
setControllerCallback
public MediaController.Builder setControllerCallback (Executor executor, MediaController.ControllerCallback callback)
Sets the callback for the controller and its executor.
Parameters | |
---|---|
executor |
Executor : callback executor |
callback |
MediaController.ControllerCallback : controller callback. |
Returns | |
---|---|
MediaController.Builder |
the Builder to allow chaining |
setSessionCompatToken
public MediaController.Builder setSessionCompatToken (MediaSessionCompat.Token compatToken)
Sets the MediaSessionCompat.Token
for the controller to connect to.
When this method is called, the SessionToken
which was set by calling
ERROR(/#setSessionToken(SessionToken))
is removed.
Parameters | |
---|---|
compatToken |
MediaSessionCompat.Token : token to connect to |
Returns | |
---|---|
MediaController.Builder |
the Builder to allow chaining |
setSessionToken
public MediaController.Builder setSessionToken (SessionToken token)
Sets the SessionToken
for the controller to connect to.
When this method is called, the MediaSessionCompat.Token
which was set by calling
ERROR(/#setSessionCompatToken)
is removed.
Detailed behavior of the MediaController
differs according to the type of the
token as follows.
- Connected to a
SessionToken.TYPE_SESSION
tokenThe controller connects to the specified session directly. It's recommended when you're sure which session to control, or a you've got token directly from the session app.
This can be used only when the session for the token is running. Once the session is closed, the token becomes unusable.
- Connected to a
SessionToken.TYPE_SESSION_SERVICE
orSessionToken.TYPE_LIBRARY_SERVICE
The controller connects to the session provided by the
MediaSessionService.onGetSession(ControllerInfo)
. It's up to the service's decision which session would be returned for the connection. Use theERROR(/#getConnectedSessionToken())
to know the connected session.This can be used regardless of the session app is running or not. The controller would bind to the service while connected to wake up and keep the service process running.
Parameters | |
---|---|
token |
SessionToken : token to connect to |
Returns | |
---|---|
MediaController.Builder |
the Builder to allow chaining |