MediaBrowserCompat

public final class MediaBrowserCompat
extends Object

java.lang.Object
   ↳ android.support.v4.media.MediaBrowserCompat


Browses media content offered by a MediaBrowserServiceCompat.

The app targeting API level 30 or higher must include a <queries> element in their manifest to connect to a media browser service in another app. See the following example and this guide for more information.

<!-- As an intent action -->
 <intent>
   <action android:name="android.media.browse.MediaBrowserService" />
 </intent>
 <!-- Or, as a package name -->
 <package android:name="package_name_of_the_other_app" />
 

This object is not thread-safe. All calls should happen on the thread on which the browser was constructed. All callback methods will be called from the thread on which the browser was constructed.

Developer Guides

For information about building your media application, read the Media Apps developer guide.

Summary

Nested classes

class MediaBrowserCompat.ConnectionCallback

Callbacks for connection related events. 

class MediaBrowserCompat.CustomActionCallback

Callback for receiving the result of MediaBrowserCompat.sendCustomAction(String, Bundle, MediaBrowserCompat.CustomActionCallback)

class MediaBrowserCompat.ItemCallback

Callback for receiving the result of MediaBrowserCompat.getItem(String, MediaBrowserCompat.ItemCallback)

class MediaBrowserCompat.MediaItem

A class with information on a single media item for use in browsing/searching media. 

class MediaBrowserCompat.SearchCallback

Callback for receiving the result of MediaBrowserCompat.search(String, Bundle, MediaBrowserCompat.SearchCallback)

class MediaBrowserCompat.SubscriptionCallback

Callbacks for subscription related events. 

Constants

String CUSTOM_ACTION_DOWNLOAD

Predefined custom action to ask the connected service to download a specific MediaBrowserCompat.MediaItem for offline playback.

String CUSTOM_ACTION_REMOVE_DOWNLOADED_FILE

Predefined custom action to ask the connected service to remove the downloaded file of MediaBrowserCompat.MediaItem by the download action.

String EXTRA_DOWNLOAD_PROGRESS

Used as a float extra field to denote the current progress during download.

String EXTRA_MEDIA_ID

Used as a string extra field to denote the target MediaBrowserCompat.MediaItem.

String EXTRA_PAGE

Used as an int extra field to denote the page number to subscribe.

String EXTRA_PAGE_SIZE

Used as an int extra field to denote the number of media items in a page.

Public constructors

MediaBrowserCompat(Context context, ComponentName serviceComponent, MediaBrowserCompat.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, MediaBrowserCompat.ItemCallback cb)

Retrieves a specific MediaBrowserCompat.MediaItem from the connected service.

String getRoot()

Gets the root id.

ComponentName getServiceComponent()

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

MediaSessionCompat.Token getSessionToken()

Gets the media session token associated with the media browser.

boolean isConnected()

Returns whether the browser is connected to the service.

void search(String query, Bundle extras, MediaBrowserCompat.SearchCallback callback)

Searches media items from the connected service.

void sendCustomAction(String action, Bundle extras, MediaBrowserCompat.CustomActionCallback callback)

Sends a custom action to the connected service.

void subscribe(String parentId, Bundle options, MediaBrowserCompat.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, MediaBrowserCompat.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, MediaBrowserCompat.SubscriptionCallback callback)

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

Inherited methods