MediaController.Builder
public final class MediaController.Builder
A builder for MediaController.
Summary
Public constructors |
|---|
Builder(Context context, SessionToken token)Creates a builder for |
Public methods |
|
|---|---|
ListenableFuture<MediaController> |
Builds a |
MediaController.Builder |
@UnstableApiSets the timeout after which updates from the platform session callbacks are applied to the browser, in milliseconds. |
MediaController.Builder |
Sets a |
MediaController.Builder |
@UnstableApiSets a |
MediaController.Builder |
@CanIgnoreReturnValueSets connection hints for the controller. |
MediaController.Builder |
Sets a listener for the controller. |
MediaController.Builder |
@UnstableApiSets the max number of commands the controller supports per media item. |
Public constructors
Builder
public Builder(Context context, SessionToken token)
Creates a builder for MediaController.
The detailed behavior of the MediaController differs depending on the type of the token as follows.
TYPE_SESSION: The controller connects to the specified session directly. It's recommended when you're sure which session to control, or you've got a 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.TYPE_SESSION_SERVICEorTYPE_LIBRARY_SERVICE: The controller connects to the session provided by theonGetSessionoronGetSession. It's up to the service to decide which session should be returned for the connection. Use thegetConnectedTokento know the connected session. This can be used regardless of whether the session app is running or not. The controller will bind to the service as long as it's connected to wake up and keep the service process running.
| Parameters | |
|---|---|
Context context |
The context. |
SessionToken token |
The token to connect to. |
Public methods
buildAsync
public ListenableFuture<MediaController> buildAsync()
Builds a MediaController asynchronously.
The controller instance can be obtained like the following example:
MediaController.Builder builder = ...;
ListenableFuture<MediaController> future = builder.buildAsync();
future.addListener(() -> {
try {
MediaController controller = future.get();
// The session accepted the connection.
} catch (ExecutionException e) {
if (e.getCause() instanceof SecurityException) {
// The session rejected the connection.
}
}
}, ContextCompat.getMainExecutor());The future must be kept by callers until the future is complete to get the controller instance. Otherwise, the future might be garbage collected and the listener added by addListener would never be called.
| Returns | |
|---|---|
ListenableFuture<MediaController> |
A future of the controller instance. |
experimentalSetPlatformSessionCallbackAggregationTimeoutMs
@UnstableApi
@CanIgnoreReturnValue
public MediaController.Builder experimentalSetPlatformSessionCallbackAggregationTimeoutMs(
long platformSessionCallbackAggregationTimeoutMs
)
Sets the timeout after which updates from the platform session callbacks are applied to the browser, in milliseconds.
The default is 100ms.
| Parameters | |
|---|---|
long platformSessionCallbackAggregationTimeoutMs |
The timeout, in milliseconds. |
| Returns | |
|---|---|
MediaController.Builder |
tThe builder to allow chaining. |
setApplicationLooper
@CanIgnoreReturnValue
public MediaController.Builder setApplicationLooper(Looper looper)
Sets a Looper that must be used for all calls to the Player methods and that is used to call Player.Listener methods on. The myLooper current looper} at that time this builder is created will be used if not specified. The main looper will be used if the current looper doesn't exist.
| Parameters | |
|---|---|
Looper looper |
The looper. |
| Returns | |
|---|---|
MediaController.Builder |
The builder to allow chaining. |
setBitmapLoader
@UnstableApi
@CanIgnoreReturnValue
public MediaController.Builder setBitmapLoader(BitmapLoader bitmapLoader)
Sets a BitmapLoader for the MediaController to decode bitmaps from compressed binary data. If not set, a CacheBitmapLoader that wraps a DataSourceBitmapLoader will be used.
| Parameters | |
|---|---|
BitmapLoader bitmapLoader |
The bitmap loader. |
| Returns | |
|---|---|
MediaController.Builder |
The builder to allow chaining. |
setConnectionHints
@CanIgnoreReturnValue
public MediaController.Builder setConnectionHints(Bundle connectionHints)
Sets connection hints for the controller.
The hints are session-specific arguments sent to the session when connecting. The contents of this bundle may affect the connection result.
The hints are only used when connecting to the MediaSession. They will be ignored when connecting to android.support.v4.media.session.MediaSessionCompat.
| Parameters | |
|---|---|
Bundle connectionHints |
A bundle containing the connection hints. |
| Returns | |
|---|---|
MediaController.Builder |
The builder to allow chaining. |
setListener
@CanIgnoreReturnValue
public MediaController.Builder setListener(MediaController.Listener listener)
Sets a listener for the controller.
| Parameters | |
|---|---|
MediaController.Listener listener |
The listener. |
| Returns | |
|---|---|
MediaController.Builder |
The builder to allow chaining. |
setMaxCommandsForMediaItems
@UnstableApi
@CanIgnoreReturnValue
public MediaController.Builder setMaxCommandsForMediaItems(int maxCommandsForMediaItems)
Sets the max number of commands the controller supports per media item.
Must be greater or equal to 0. The default is 0.
| Parameters | |
|---|---|
int maxCommandsForMediaItems |
The max number of commands per media item. |
| Returns | |
|---|---|
MediaController.Builder |
The builder to allow chaining. |