public final class MediaBrowser extends Object
This object is not thread-safe. All calls should happen on the thread on which the browser was constructed.
These are the current standard fields that can be used as extra data via
subscribe(String, Bundle, SubscriptionCallback)
,
unsubscribe(String, SubscriptionCallback)
, and
MediaBrowser.SubscriptionCallback.onChildrenLoaded(String, List, Bundle)
.
Modifier and Type | Class and Description |
---|---|
static class |
MediaBrowser.ConnectionCallback
Callbacks for connection related events.
|
static class |
MediaBrowser.ItemCallback
Callback for receiving the result of
getItem(java.lang.String, android.media.browse.MediaBrowser.ItemCallback) . |
static class |
MediaBrowser.MediaItem
A class with information on a single media item for use in browsing media.
|
static class |
MediaBrowser.SubscriptionCallback
Callbacks for subscription related events.
|
Modifier and Type | Field and Description |
---|---|
static String |
EXTRA_PAGE
Used as an int extra field to denote the page number to subscribe.
|
static String |
EXTRA_PAGE_SIZE
Used as an int extra field to denote the number of media items in a page.
|
Constructor and Description |
---|
MediaBrowser(Context context,
ComponentName serviceComponent,
MediaBrowser.ConnectionCallback callback,
Bundle rootHints)
Creates a media browser for the specified media browse service.
|
Modifier and Type | Method and Description |
---|---|
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,
Bundle options,
MediaBrowser.SubscriptionCallback callback)
Queries with service-specific arguments for information about the media items
that are contained within the specified id and subscribes to receive updates
when they change.
|
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.
|
void |
unsubscribe(String parentId,
MediaBrowser.SubscriptionCallback callback)
Unsubscribes for changes to the children of the specified media id through a callback.
|
public static final String EXTRA_PAGE
EXTRA_PAGE
should be greater than or equal to 0.EXTRA_PAGE_SIZE
,
Constant Field Valuespublic static final String EXTRA_PAGE_SIZE
EXTRA_PAGE_SIZE
should be greater than or equal to 1.EXTRA_PAGE
,
Constant Field Valuespublic MediaBrowser(Context context, ComponentName serviceComponent, MediaBrowser.ConnectionCallback callback, Bundle rootHints)
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.MediaBrowserService.BrowserRoot.EXTRA_RECENT
,
MediaBrowserService.BrowserRoot.EXTRA_OFFLINE
,
MediaBrowserService.BrowserRoot.EXTRA_SUGGESTED
public void connect()
The connection callback specified in the constructor will be invoked when the connection completes or fails.
public void disconnect()
public boolean isConnected()
public ComponentName getServiceComponent()
public String getRoot()
Note that the root id may become invalid or change when the browser is disconnected.
IllegalStateException
- if not connected.public Bundle getExtras()
IllegalStateException
- if not connected.public MediaSession.Token getSessionToken()
Note that the session token may become invalid or change when the browser is disconnected.
IllegalStateException
- if not connected.public void subscribe(String parentId, MediaBrowser.SubscriptionCallback callback)
The list of subscriptions is maintained even when not connected and is restored after the 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.
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 subscribe(String parentId, Bundle options, MediaBrowser.SubscriptionCallback callback)
The list of subscriptions is maintained even when not connected and is restored after the 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.
parentId
- The id of the parent media item whose list of children
will be subscribed.options
- A bundle of service-specific arguments to send to the media
browse service. The contents of this bundle may affect the
information returned when browsing.callback
- The callback to receive the list of children.public void unsubscribe(String parentId)
The query callback will no longer be invoked for results associated with this id once this method returns.
parentId
- The id of the parent media item whose list of children
will be unsubscribed.public void unsubscribe(String parentId, MediaBrowser.SubscriptionCallback callback)
The query callback will no longer be invoked for results associated with this id once this method returns.
parentId
- The id of the parent media item whose list of children
will be unsubscribed.callback
- A callback sent to the media browse service to subscribe.public void getItem(String mediaId, MediaBrowser.ItemCallback cb)
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.mediaId
- The id of the item to retrieve.cb
- The callback to receive the result on.