Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

MediaLibrarySessionCallback

class MediaLibrarySessionCallback : MediaSession2.SessionCallback
kotlin.Any
   ↳ androidx.media2.MediaSession2.SessionCallback
   ↳ androidx.media2.MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback

Callback for the MediaLibrarySession.

Summary

Public constructors

Callback for the MediaLibrarySession.

Public methods
open MediaLibraryService2.LibraryRoot?
onGetLibraryRoot(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @Nullable rootHints: Bundle?)

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

open Unit
onSearch(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull query: String, @Nullable extras: Bundle?)

Called when a controller requests search.

open MutableList<MediaItem2!>?
onGetSearchResult(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull query: String, page: Int, pageSize: Int, @Nullable extras: Bundle?)

Called to get the search result.

open Unit
onUnsubscribe(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull parentId: String)

Called when a controller unsubscribes to the parent.

open Unit
onSubscribe(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull parentId: String, @Nullable extras: Bundle?)

Called when a controller subscribes to the parent.

open MediaItem2?
onGetItem(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull mediaId: String)

Called to get an item.

open MutableList<MediaItem2!>?
onGetChildren(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull parentId: String, page: Int, pageSize: Int, @Nullable extras: Bundle?)

Called to get children of given parent id.

Inherited functions

Public constructors

<init>

MediaLibrarySessionCallback()

Callback for the MediaLibrarySession.

Public methods

onGetLibraryRoot

@Nullable open fun onGetLibraryRoot(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @Nullable rootHints: Bundle?): MediaLibraryService2.LibraryRoot?

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.

Note: this callback may be called on the main thread, regardless of the callback executor.

Parameters
session MediaLibraryService2.MediaLibrarySession: the session for this event
controller MediaLibraryService2.MediaLibrarySession: information of the controller requesting access to browse media.
rootHints MediaLibraryService2.MediaLibrarySession: An optional bundle of service-specific arguments to send to the media library 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
MediaLibraryService2.LibraryRoot?: The LibraryRoot for accessing this app's content or null.

onSearch

open fun onSearch(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull query: String, @Nullable extras: Bundle?): Unit

Called when a controller requests search.

Parameters
session MediaLibraryService2.MediaLibrarySession: the session for this event
controller MediaLibraryService2.MediaLibrarySession: controller
query MediaLibraryService2.MediaLibrarySession: The search query sent from the media browser. It contains keywords separated by space.
extras MediaLibraryService2.MediaLibrarySession: The bundle of service-specific arguments sent from the media browser.

onGetSearchResult

@Nullable open fun onGetSearchResult(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull query: String, page: Int, pageSize: Int, @Nullable extras: Bundle?): MutableList<MediaItem2!>?

Called to get the search result. Return search result here for the browser which has requested search previously.

Return an empty list for no search result, and return null for the error.

This may be called with a query that hasn't called with onSearch, especially when android.support.v4.media.MediaBrowserCompat#search is used.

Parameters
session MediaLibraryService2.MediaLibrarySession: the session for this event
controller MediaLibraryService2.MediaLibrarySession: controller
query MediaLibraryService2.MediaLibrarySession: The search query which was previously sent through onSearch(MediaLibrarySession, ControllerInfo, String, Bundle).
page MediaLibraryService2.MediaLibrarySession: page number. Starts from 0.
pageSize MediaLibraryService2.MediaLibrarySession: page size. Should be greater or equal to 1.
extras MediaLibraryService2.MediaLibrarySession: The bundle of service-specific arguments sent from the media browser.
Return
MutableList<MediaItem2!>?: search result. null for error.

onUnsubscribe

open fun onUnsubscribe(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull parentId: String): Unit

Called when a controller unsubscribes to the parent.

Interoperability: This wouldn't be called if MediaBrowser#unsubscribe is called while works well with android.support.v4.media.MediaBrowserCompat#unsubscribe.

Parameters
session MediaLibraryService2.MediaLibrarySession: the session for this event
controller MediaLibraryService2.MediaLibrarySession: controller
parentId MediaLibraryService2.MediaLibrarySession: parent id

onSubscribe

open fun onSubscribe(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull parentId: String, @Nullable extras: Bundle?): Unit

Called when a controller subscribes to the parent.

It's your responsibility to keep subscriptions by your own and call MediaLibrarySession#notifyChildrenChanged( * ControllerInfo, String, int, Bundle) when the parent is changed.

Interoperability: This will be called when android.support.v4.media.MediaBrowserCompat#subscribe is called. However, this won't be called when MediaBrowser#subscribe is called.

Parameters
session MediaLibraryService2.MediaLibrarySession: the session for this event
controller MediaLibraryService2.MediaLibrarySession: controller
parentId MediaLibraryService2.MediaLibrarySession: parent id
extras MediaLibraryService2.MediaLibrarySession: extra bundle

onGetItem

@Nullable open fun onGetItem(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull mediaId: String): MediaItem2?

Called to get an item. Return result here for the browser.

Return null for no result or error.

Parameters
session MediaLibraryService2.MediaLibrarySession: the session for this event
controller MediaLibraryService2.MediaLibrarySession: controller
mediaId MediaLibraryService2.MediaLibrarySession: item id to get media item.
Return
MediaItem2?: a media item. null for no result or error.

onGetChildren

@Nullable open fun onGetChildren(@NonNull session: MediaLibraryService2.MediaLibrarySession, @NonNull controller: MediaSession2.ControllerInfo, @NonNull parentId: String, page: Int, pageSize: Int, @Nullable extras: Bundle?): MutableList<MediaItem2!>?

Called to get children of given parent id. Return the children here for the browser.

Return an empty list for no children, and return null for the error.

Parameters
session MediaLibraryService2.MediaLibrarySession: the session for this event
controller MediaLibraryService2.MediaLibrarySession: controller
parentId MediaLibraryService2.MediaLibrarySession: parent id to get children
page MediaLibraryService2.MediaLibrarySession: page number. Starts from 0.
pageSize MediaLibraryService2.MediaLibrarySession: page size. Should be greater or equal to 1.
extras MediaLibraryService2.MediaLibrarySession: extra bundle
Return
MutableList<MediaItem2!>?: list of children. Can be null.