public final class SessionCallbackBuilder extends Object
MediaSession.SessionCallback
with various collaborators.MediaSession.SessionCallback
Modifier and Type | Class | Description |
---|---|---|
static interface |
SessionCallbackBuilder.AllowedCommandProvider |
Provides allowed commands for
MediaController . |
static interface |
SessionCallbackBuilder.CustomCommandProvider |
Callbacks for querying what custom commands are supported, and for handling a custom command
when a controller sends it.
|
static class |
SessionCallbackBuilder.DefaultAllowedCommandProvider |
Default implementation of
SessionCallbackBuilder.AllowedCommandProvider that behaves as follows:
Accepts connection requests from controller if any of the following conditions are met:
Controller is in the same package as the session. |
static interface |
SessionCallbackBuilder.DisconnectedCallback |
Callback for handling controller disconnection.
|
static class |
SessionCallbackBuilder.MediaIdMediaItemProvider |
A
SessionCallbackBuilder.MediaItemProvider that creates media items containing only a media ID. |
static interface |
SessionCallbackBuilder.MediaItemProvider |
Provides the
MediaItem . |
static interface |
SessionCallbackBuilder.PostConnectCallback |
Callback for handling extra initialization after the connection.
|
static interface |
SessionCallbackBuilder.RatingCallback |
Callback receiving a user rating for a specified media id.
|
static interface |
SessionCallbackBuilder.SkipCallback |
Callback receiving skip backward and skip forward.
|
Modifier and Type | Field | Description |
---|---|---|
static int |
DEFAULT_SEEK_TIMEOUT_MS |
Default timeout value for
setSeekTimeoutMs(int) . |
Constructor | Description |
---|---|
SessionCallbackBuilder(Context context,
SessionPlayerConnector sessionPlayerConnector) |
Creates a new builder.
|
public static final int DEFAULT_SEEK_TIMEOUT_MS
setSeekTimeoutMs(int)
.public SessionCallbackBuilder(Context context, SessionPlayerConnector sessionPlayerConnector)
The builder uses the following default values:
SessionCallbackBuilder.AllowedCommandProvider
: SessionCallbackBuilder.DefaultAllowedCommandProvider
DEFAULT_SEEK_TIMEOUT_MS
null
or 0
would be used to disallow relevant features.context
- A context.sessionPlayerConnector
- A session player connector to handle incoming calls from the
controller.public SessionCallbackBuilder setRatingCallback(@Nullable SessionCallbackBuilder.RatingCallback ratingCallback)
SessionCallbackBuilder.RatingCallback
to handle user ratings.ratingCallback
- A rating callback.MediaSession.SessionCallback.onSetRating(MediaSession, ControllerInfo, String, Rating)
,
MediaController.setRating(String, Rating)
public SessionCallbackBuilder setCustomCommandProvider(@Nullable SessionCallbackBuilder.CustomCommandProvider customCommandProvider)
SessionCallbackBuilder.CustomCommandProvider
to handle incoming custom commands.customCommandProvider
- A custom command provider.MediaSession.SessionCallback.onCustomCommand(MediaSession, ControllerInfo, SessionCommand,
Bundle)
,
MediaController.sendCustomCommand(SessionCommand, Bundle)
public SessionCallbackBuilder setMediaItemProvider(@Nullable SessionCallbackBuilder.MediaItemProvider mediaItemProvider)
SessionCallbackBuilder.MediaItemProvider
that will convert media ids to MediaItems
.mediaItemProvider
- The media item provider.MediaSession.SessionCallback.onCreateMediaItem(MediaSession, ControllerInfo, String)
,
MediaController.addPlaylistItem(int, String)
,
MediaController.replacePlaylistItem(int, String)
,
MediaController.setMediaItem(String)
,
MediaController.setPlaylist(List, MediaMetadata)
public SessionCallbackBuilder setAllowedCommandProvider(@Nullable SessionCallbackBuilder.AllowedCommandProvider allowedCommandProvider)
SessionCallbackBuilder.AllowedCommandProvider
to provide allowed commands for controllers.allowedCommandProvider
- A allowed command provider.public SessionCallbackBuilder setSkipCallback(@Nullable SessionCallbackBuilder.SkipCallback skipCallback)
SessionCallbackBuilder.SkipCallback
to handle skip backward and skip forward.skipCallback
- The skip callback.MediaSession.SessionCallback.onSkipBackward(MediaSession, ControllerInfo)
,
MediaSession.SessionCallback.onSkipForward(MediaSession, ControllerInfo)
,
MediaController.skipBackward()
,
MediaController.skipForward()
public SessionCallbackBuilder setPostConnectCallback(@Nullable SessionCallbackBuilder.PostConnectCallback postConnectCallback)
SessionCallbackBuilder.PostConnectCallback
to handle extra initialization after the connection.postConnectCallback
- The post connect callback.MediaSession.SessionCallback.onPostConnect(MediaSession, ControllerInfo)
public SessionCallbackBuilder setDisconnectedCallback(@Nullable SessionCallbackBuilder.DisconnectedCallback disconnectedCallback)
SessionCallbackBuilder.DisconnectedCallback
to handle cleaning up controller.disconnectedCallback
- The disconnected callback.MediaSession.SessionCallback.onDisconnected(MediaSession, ControllerInfo)
public SessionCallbackBuilder setRewindIncrementMs(int rewindMs)
rewindMs
- The rewind increment in milliseconds. A non-positive value will cause the
rewind to be disabled.MediaSession.SessionCallback.onRewind(MediaSession, MediaSession.ControllerInfo)
,
setSeekTimeoutMs(int)
public SessionCallbackBuilder setFastForwardIncrementMs(int fastForwardMs)
fastForwardMs
- The fast forward increment in milliseconds. A non-positive value will
cause the fast forward to be disabled.MediaSession.SessionCallback.onFastForward(MediaSession, MediaSession.ControllerInfo)
,
setSeekTimeoutMs(int)
public SessionCallbackBuilder setSeekTimeoutMs(int seekTimeoutMs)
0
for no
timeout. If a timeout is set, controllers will receive an error if the session's call to SessionPlayer.seekTo(long)
takes longer than this amount of time.seekTimeoutMs
- A timeout for SessionPlayer.seekTo(long)
. A non-positive value will wait
forever.public androidx.media2.session.MediaSession.SessionCallback build()
MediaSession.SessionCallback
.