MediaBrowser.Builder
public final class MediaBrowser.Builder
A builder for MediaBrowser.
Summary
Public constructors |
|---|
Builder(Context context, SessionToken token)Creates a builder for |
Public methods |
|
|---|---|
ListenableFuture<MediaBrowser> |
Builds a |
MediaBrowser.Builder |
@UnstableApiSets the timeout after which updates from the platform session callbacks are applied to the browser, in milliseconds. |
MediaBrowser.Builder |
Sets a |
MediaBrowser.Builder |
@UnstableApiSets a |
MediaBrowser.Builder |
@CanIgnoreReturnValueSets connection hints for the browser. |
MediaBrowser.Builder |
Sets a listener for the browser. |
MediaBrowser.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 MediaBrowser.
The type of SessionToken for a browser would typically be a TYPE_LIBRARY_SERVICE but it may be other types. The detailed behavior depending on the type is described in Builder.
| Parameters | |
|---|---|
Context context |
The context. |
SessionToken token |
The token to connect to. |
Public methods
buildAsync
public ListenableFuture<MediaBrowser> buildAsync()
Builds a MediaBrowser asynchronously.
The browser instance can be obtained like the following example:
MediaBrowser.Builder builder = new MediaBrowser.Builder(context, sessionToken);
ListenableFuture<MediaBrowser> future = builder.buildAsync();
future.addListener(() -> {
try {
MediaBrowser browser = future.get();
// The session accepted the connection.
} catch (ExecutionException | InterruptedException e) {
if (e.getCause() instanceof SecurityException) {
// The session rejected the connection.
}
}
}, ContextCompat.getMainExecutor(context));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<MediaBrowser> |
A future of the browser instance. |
experimentalSetPlatformSessionCallbackAggregationTimeoutMs
@UnstableApi
@CanIgnoreReturnValue
public MediaBrowser.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 | |
|---|---|
MediaBrowser.Builder |
The builder to allow chaining. |
setApplicationLooper
@CanIgnoreReturnValue
public MediaBrowser.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 | |
|---|---|
MediaBrowser.Builder |
The builder to allow chaining. |
setBitmapLoader
@UnstableApi
@CanIgnoreReturnValue
public MediaBrowser.Builder setBitmapLoader(BitmapLoader bitmapLoader)
Sets a BitmapLoader for the MediaBrowser 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 | |
|---|---|
MediaBrowser.Builder |
The builder to allow chaining. |
setConnectionHints
@CanIgnoreReturnValue
public MediaBrowser.Builder setConnectionHints(Bundle connectionHints)
Sets connection hints for the browser.
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 | |
|---|---|
MediaBrowser.Builder |
The builder to allow chaining. |
setListener
@CanIgnoreReturnValue
public MediaBrowser.Builder setListener(MediaBrowser.Listener listener)
Sets a listener for the browser.
| Parameters | |
|---|---|
MediaBrowser.Listener listener |
The listener. |
| Returns | |
|---|---|
MediaBrowser.Builder |
The builder to allow chaining. |
setMaxCommandsForMediaItems
@UnstableApi
@CanIgnoreReturnValue
public MediaBrowser.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 | |
|---|---|
MediaBrowser.Builder |
The builder to allow chaining. |