Class SessionCallbackBuilder
- java.lang.Object
-
- com.google.android.exoplayer2.ext.media2.SessionCallbackBuilder
-
public final class SessionCallbackBuilder extends Object
Builds aMediaSession.SessionCallback
with various collaborators.- See Also:
MediaSession.SessionCallback
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SessionCallbackBuilder.AllowedCommandProvider
Provides allowed commands forMediaController
.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 ofSessionCallbackBuilder.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
ASessionCallbackBuilder.MediaItemProvider
that creates media items containing only a media ID.static interface
SessionCallbackBuilder.MediaItemProvider
Provides theMediaItem
.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.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_SEEK_TIMEOUT_MS
Default timeout value forsetSeekTimeoutMs(int)
.
-
Constructor Summary
Constructors Constructor Description SessionCallbackBuilder(Context context, SessionPlayerConnector sessionPlayerConnector)
Creates a new builder.
-
Method Summary
-
-
-
Field Detail
-
DEFAULT_SEEK_TIMEOUT_MS
public static final int DEFAULT_SEEK_TIMEOUT_MS
Default timeout value forsetSeekTimeoutMs(int)
.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SessionCallbackBuilder
public SessionCallbackBuilder(Context context, SessionPlayerConnector sessionPlayerConnector)
Creates a new builder.The builder uses the following default values:
SessionCallbackBuilder.AllowedCommandProvider
:SessionCallbackBuilder.DefaultAllowedCommandProvider
- Seek timeout:
DEFAULT_SEEK_TIMEOUT_MS
null
or0
would be used to disallow relevant features.- Parameters:
context
- A context.sessionPlayerConnector
- A session player connector to handle incoming calls from the controller.
-
-
Method Detail
-
setRatingCallback
public SessionCallbackBuilder setRatingCallback(@Nullable SessionCallbackBuilder.RatingCallback ratingCallback)
Sets theSessionCallbackBuilder.RatingCallback
to handle user ratings.- Parameters:
ratingCallback
- A rating callback.- Returns:
- This builder.
- See Also:
MediaSession.SessionCallback.onSetRating(MediaSession, ControllerInfo, String, Rating)
,MediaController.setRating(String, Rating)
-
setCustomCommandProvider
public SessionCallbackBuilder setCustomCommandProvider(@Nullable SessionCallbackBuilder.CustomCommandProvider customCommandProvider)
Sets theSessionCallbackBuilder.CustomCommandProvider
to handle incoming custom commands.- Parameters:
customCommandProvider
- A custom command provider.- Returns:
- This builder.
- See Also:
MediaSession.SessionCallback.onCustomCommand(MediaSession, ControllerInfo, SessionCommand, Bundle)
,MediaController.sendCustomCommand(SessionCommand, Bundle)
-
setMediaItemProvider
public SessionCallbackBuilder setMediaItemProvider(@Nullable SessionCallbackBuilder.MediaItemProvider mediaItemProvider)
Sets theSessionCallbackBuilder.MediaItemProvider
that will convert media ids toMediaItems
.- Parameters:
mediaItemProvider
- The media item provider.- Returns:
- This builder.
- See Also:
MediaSession.SessionCallback.onCreateMediaItem(MediaSession, ControllerInfo, String)
,MediaController.addPlaylistItem(int, String)
,MediaController.replacePlaylistItem(int, String)
,MediaController.setMediaItem(String)
,MediaController.setPlaylist(List, MediaMetadata)
-
setAllowedCommandProvider
public SessionCallbackBuilder setAllowedCommandProvider(@Nullable SessionCallbackBuilder.AllowedCommandProvider allowedCommandProvider)
Sets theSessionCallbackBuilder.AllowedCommandProvider
to provide allowed commands for controllers.- Parameters:
allowedCommandProvider
- A allowed command provider.- Returns:
- This builder.
-
setSkipCallback
public SessionCallbackBuilder setSkipCallback(@Nullable SessionCallbackBuilder.SkipCallback skipCallback)
Sets theSessionCallbackBuilder.SkipCallback
to handle skip backward and skip forward.- Parameters:
skipCallback
- The skip callback.- Returns:
- This builder.
- See Also:
MediaSession.SessionCallback.onSkipBackward(MediaSession, ControllerInfo)
,MediaSession.SessionCallback.onSkipForward(MediaSession, ControllerInfo)
,MediaController.skipBackward()
,MediaController.skipForward()
-
setPostConnectCallback
public SessionCallbackBuilder setPostConnectCallback(@Nullable SessionCallbackBuilder.PostConnectCallback postConnectCallback)
Sets theSessionCallbackBuilder.PostConnectCallback
to handle extra initialization after the connection.- Parameters:
postConnectCallback
- The post connect callback.- Returns:
- This builder.
- See Also:
MediaSession.SessionCallback.onPostConnect(MediaSession, ControllerInfo)
-
setDisconnectedCallback
public SessionCallbackBuilder setDisconnectedCallback(@Nullable SessionCallbackBuilder.DisconnectedCallback disconnectedCallback)
Sets theSessionCallbackBuilder.DisconnectedCallback
to handle cleaning up controller.- Parameters:
disconnectedCallback
- The disconnected callback.- Returns:
- This builder.
- See Also:
MediaSession.SessionCallback.onDisconnected(MediaSession, ControllerInfo)
-
setRewindIncrementMs
public SessionCallbackBuilder setRewindIncrementMs(int rewindMs)
Sets the rewind increment in milliseconds.- Parameters:
rewindMs
- The rewind increment in milliseconds. A non-positive value will cause the rewind to be disabled.- Returns:
- This builder.
- See Also:
MediaSession.SessionCallback.onRewind(MediaSession, MediaSession.ControllerInfo)
,setSeekTimeoutMs(int)
-
setFastForwardIncrementMs
public SessionCallbackBuilder setFastForwardIncrementMs(int fastForwardMs)
Sets the fast forward increment in milliseconds.- Parameters:
fastForwardMs
- The fast forward increment in milliseconds. A non-positive value will cause the fast forward to be disabled.- Returns:
- This builder.
- See Also:
MediaSession.SessionCallback.onFastForward(MediaSession, MediaSession.ControllerInfo)
,setSeekTimeoutMs(int)
-
setSeekTimeoutMs
public SessionCallbackBuilder setSeekTimeoutMs(int seekTimeoutMs)
Sets the timeout in milliseconds for fast forward and rewind operations, or0
for no timeout. If a timeout is set, controllers will receive an error if the session's call toSessionPlayer.seekTo(long)
takes longer than this amount of time.- Parameters:
seekTimeoutMs
- A timeout forSessionPlayer.seekTo(long)
. A non-positive value will wait forever.- Returns:
- This builder.
-
build
public androidx.media2.session.MediaSession.SessionCallback build()
BuildsMediaSession.SessionCallback
.- Returns:
- A new callback for a media session.
-
-