Android APIs
public final class

MediaBrowser

extends Object
java.lang.Object
   ↳ android.media.browse.MediaBrowser

Class Overview

Browses media content offered by a link MediaBrowserService.

This object is not thread-safe. All calls should happen on the thread on which the browser was constructed.

Summary

Nested Classes
class MediaBrowser.ConnectionCallback Callbacks for connection related events. 
class MediaBrowser.ItemCallback Callback for receiving the result of getItem(String, MediaBrowser.ItemCallback)
class MediaBrowser.MediaItem  
class MediaBrowser.SubscriptionCallback Callbacks for subscription related events. 
Public Constructors
MediaBrowser(Context context, ComponentName serviceComponent, MediaBrowser.ConnectionCallback callback, Bundle rootHints)
Creates a media browser for the specified media browse service.
Public Methods
void connect()
Connects to the media browse service.
void disconnect()
Disconnects from the media browse service.
Bundle getExtras()
Gets any extras for the media service.
void getItem(String mediaId, MediaBrowser.ItemCallback cb)
Retrieves a specific MediaBrowser.MediaItem from the connected service.
String getRoot()
Gets the root id.
ComponentName getServiceComponent()
Gets the service component that the media browser is connected to.
MediaSession.Token getSessionToken()
Gets the media session token associated with the media browser.
boolean isConnected()
Returns whether the browser is connected to the service.
void subscribe(String parentId, MediaBrowser.SubscriptionCallback callback)
Queries for information about the media items that are contained within the specified id and subscribes to receive updates when they change.
void unsubscribe(String parentId)
Unsubscribes for changes to the children of the specified media id.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public MediaBrowser (Context context, ComponentName serviceComponent, MediaBrowser.ConnectionCallback callback, Bundle rootHints)

Added in API level 21

Creates a media browser for the specified media browse service.

Parameters
context The context.
serviceComponent The component name of the media browse service.
callback The connection callback.
rootHints An optional bundle of service-specific arguments to send to the media browse service when connecting and retrieving the root id for browsing, or null if none. The contents of this bundle may affect the information returned when browsing.

Public Methods

public void connect ()

Added in API level 21

Connects to the media browse service.

The connection callback specified in the constructor will be invoked when the connection completes or fails.

public void disconnect ()

Added in API level 21

Disconnects from the media browse service. After this, no more callbacks will be received.

public Bundle getExtras ()

Added in API level 21

Gets any extras for the media service.

Throws
IllegalStateException if not connected.

public void getItem (String mediaId, MediaBrowser.ItemCallback cb)

Added in API level 23

Retrieves a specific MediaBrowser.MediaItem from the connected service. Not all services may support this, so falling back to subscribing to the parent's id should be used when unavailable.

Parameters
mediaId The id of the item to retrieve.
cb The callback to receive the result on.

public String getRoot ()

Added in API level 21

Gets the root id.

Note that the root id may become invalid or change when when the browser is disconnected.

Throws
IllegalStateException if not connected.

public ComponentName getServiceComponent ()

Added in API level 21

Gets the service component that the media browser is connected to.

public MediaSession.Token getSessionToken ()

Added in API level 21

Gets the media session token associated with the media browser.

Note that the session token may become invalid or change when when the browser is disconnected.

Returns
  • The session token for the browser, never null.
Throws
IllegalStateException if not connected.

public boolean isConnected ()

Added in API level 21

Returns whether the browser is connected to the service.

public void subscribe (String parentId, MediaBrowser.SubscriptionCallback callback)

Added in API level 21

Queries for information about the media items that are contained within the specified id and subscribes to receive updates when they change.

The list of subscriptions is maintained even when not connected and is restored after reconnection. It is ok to subscribe while not connected but the results will not be returned until the connection completes.

If the id is already subscribed with a different callback then the new callback will replace the previous one and the child data will be reloaded.

Parameters
parentId The id of the parent media item whose list of children will be subscribed.
callback The callback to receive the list of children.

public void unsubscribe (String parentId)

Added in API level 21

Unsubscribes for changes to the children of the specified media id.

The query callback will no longer be invoked for results associated with this id once this method returns.

Parameters
parentId The id of the parent media item whose list of children will be unsubscribed.