Added in API level 21

MediaBrowserService

abstract class MediaBrowserService : Service
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ android.service.media.MediaBrowserService

Base class for media browser services.

Media browser services enable applications to browse media content provided by an application and ask the application to start playing it. They may also be used to control content that is already playing by way of a MediaSession.

To extend this class, you must declare the service in your manifest file with an intent filter with the SERVICE_INTERFACE action. For example:

<service android:name=".MyMediaBrowserService"
           android:label="@string/service_name" >
      <intent-filter>
          <action android:name="android.media.browse.MediaBrowserService" />
      </intent-filter>
  </service>
  

Summary

Nested classes

Contains information that the browser service needs to send to the client when first connected.

open

Completion handler for asynchronous callback methods in MediaBrowserService.

Constants
static String

The Intent that must be declared as handled by the service.

Inherited constants
Public constructors

Public methods
open Unit
dump(fd: FileDescriptor!, writer: PrintWriter!, args: Array<String!>!)

Bundle!

Gets the root hints sent from the currently connected MediaBrowser.

MediaSessionManager.RemoteUserInfo!

Gets the browser information who sent the current request.

open MediaSession.Token?

Gets the session token, or null if it has not yet been created or if it has been destroyed.

open Unit

Notifies all connected media browsers that the children of the specified parent id have changed in some way.

open Unit
notifyChildrenChanged(parentId: String, options: Bundle)

Notifies all connected media browsers that the children of the specified parent id have changed in some way.

open IBinder?
onBind(intent: Intent!)

open Unit

abstract MediaBrowserService.BrowserRoot?
onGetRoot(clientPackageName: String, clientUid: Int, rootHints: Bundle?)

Called to get the root information for browsing by a particular client.

abstract Unit

Called to get information about the children of a media item.

open Unit

Called to get information about the children of a media item.

open Unit

Called to get information about a specific media item.

open Unit

Call to set the media session.

Inherited functions

Constants

SERVICE_INTERFACE

Added in API level 21
static val SERVICE_INTERFACE: String

The Intent that must be declared as handled by the service.

Value: "android.media.browse.MediaBrowserService"

Public constructors

MediaBrowserService

MediaBrowserService()

Public methods

dump

Added in API level 21
open fun dump(
    fd: FileDescriptor!,
    writer: PrintWriter!,
    args: Array<String!>!
): Unit
Parameters
fd FileDescriptor!: The raw file descriptor that the dump is being sent to.
writer PrintWriter!: The PrintWriter to which you should dump your state. This will be closed for you after you return.
args Array<String!>!: additional arguments to the dump request.

getBrowserRootHints

Added in API level 24
fun getBrowserRootHints(): Bundle!

Gets the root hints sent from the currently connected MediaBrowser. The root hints are service-specific arguments included in an optional bundle sent to the media browser 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.

Exceptions
java.lang.IllegalStateException If this method is called outside of onGetRoot or #onLoadChildren or onLoadItem.

getCurrentBrowserInfo

Added in API level 28
fun getCurrentBrowserInfo(): MediaSessionManager.RemoteUserInfo!

Gets the browser information who sent the current request.

Exceptions
java.lang.IllegalStateException If this method is called outside of onGetRoot or #onLoadChildren or onLoadItem.

getSessionToken

Added in API level 21
open fun getSessionToken(): MediaSession.Token?

Gets the session token, or null if it has not yet been created or if it has been destroyed.

notifyChildrenChanged

Added in API level 21
open fun notifyChildrenChanged(parentId: String): Unit

Notifies all connected media browsers that the children of the specified parent id have changed in some way. This will cause browsers to fetch subscribed content again.

Parameters
parentId String: The id of the parent media item whose children changed. This value cannot be null.

notifyChildrenChanged

Added in API level 24
open fun notifyChildrenChanged(
    parentId: String,
    options: Bundle
): Unit

Notifies all connected media browsers that the children of the specified parent id have changed in some way. This will cause browsers to fetch subscribed content again.

Parameters
parentId String: The id of the parent media item whose children changed. This value cannot be null.
options Bundle: The bundle of service-specific arguments to send to the media browser. The contents of this bundle may contain the information about the change. This value cannot be null.

onBind

Added in API level 21
open fun onBind(intent: Intent!): IBinder?
Parameters
intent Intent!: The Intent that was used to bind to this service, as given to android.content.Context#bindService. Note that any extras that were included with the Intent at that point will not be seen here.
Return
IBinder? Return an IBinder through which clients can call on to the service.

onCreate

Added in API level 21
open fun onCreate(): Unit

onGetRoot

Added in API level 21
abstract fun onGetRoot(
    clientPackageName: String,
    clientUid: Int,
    rootHints: Bundle?
): MediaBrowserService.BrowserRoot?

Called to get the root information for browsing by a particular client.

The implementation should verify that the client package has permission to access browse media information before returning the root id; it should return null if the client is not allowed to access this information.

Parameters
clientPackageName String: The package name of the application which is requesting access to browse media. This value cannot be null.
clientUid Int: The uid of the application which is requesting access to browse media.
rootHints Bundle?: An optional bundle of service-specific arguments to send to the media browser 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.
Return
MediaBrowserService.BrowserRoot? The BrowserRoot for accessing this app's content or null.

onLoadChildren

Added in API level 21
abstract fun onLoadChildren(
    parentId: String,
    result: MediaBrowserService.Result<MutableList<MediaBrowser.MediaItem!>!>
): Unit

Called to get information about the children of a media item.

Implementations must call result.sendResult with the list of children. If loading the children will be an expensive operation that should be performed on another thread, result.detach may be called before returning from this function, and then result.sendResult called when the loading is complete.

In case the media item does not have any children, call Result#sendResult with an empty list. When the given parentId is invalid, implementations must call result.sendResult with null, which will invoke android.media.browse.MediaBrowser.SubscriptionCallback#onError.

Parameters
parentId String: The id of the parent media item whose children are to be queried. This value cannot be null.
result MediaBrowserService.Result<MutableList<MediaBrowser.MediaItem!>!>: The Result to send the list of children to. This value cannot be null.

onLoadChildren

Added in API level 24
open fun onLoadChildren(
    parentId: String,
    result: MediaBrowserService.Result<MutableList<MediaBrowser.MediaItem!>!>,
    options: Bundle
): Unit

Called to get information about the children of a media item.

Implementations must call result.sendResult with the list of children. If loading the children will be an expensive operation that should be performed on another thread, result.detach may be called before returning from this function, and then result.sendResult called when the loading is complete.

In case the media item does not have any children, call Result#sendResult with an empty list. When the given parentId is invalid, implementations must call result.sendResult with null, which will invoke android.media.browse.MediaBrowser.SubscriptionCallback#onError.

Parameters
parentId String: The id of the parent media item whose children are to be queried. This value cannot be null.
result MediaBrowserService.Result<MutableList<MediaBrowser.MediaItem!>!>: The Result to send the list of children to. This value cannot be null.
options Bundle: The bundle of service-specific arguments sent from the media browser. The information returned through the result should be affected by the contents of this bundle. This value cannot be null.

onLoadItem

Added in API level 23
open fun onLoadItem(
    itemId: String!,
    result: MediaBrowserService.Result<MediaBrowser.MediaItem!>!
): Unit

Called to get information about a specific media item.

Implementations must call result.sendResult. If loading the item will be an expensive operation result.detach may be called before returning from this function, and then result.sendResult called when the item has been loaded.

When the given itemId is invalid, implementations must call result.sendResult with null.

The default implementation will invoke MediaBrowser.ItemCallback#onError.

Parameters
itemId String!: The id for the specific android.media.browse.MediaBrowser.MediaItem.
result MediaBrowserService.Result<MediaBrowser.MediaItem!>!: The Result to send the item to.

setSessionToken

Added in API level 21
open fun setSessionToken(token: MediaSession.Token!): Unit

Call to set the media session.

This should be called as soon as possible during the service's startup. It may only be called once.

Parameters
token MediaSession.Token!: The token for the service's MediaSession.