MediaLibrarySessionCallback

class MediaLibrarySessionCallback : MediaSession.SessionCallback
kotlin.Any
   ↳ androidx.media2.session.MediaSession.SessionCallback
   ↳ androidx.media2.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback

Callback for the MediaLibrarySession.

When you return LibraryResult with media items, items must have valid MediaMetadata#METADATA_KEY_MEDIA_ID and specify MediaMetadata#METADATA_KEY_BROWSABLE and MediaMetadata#METADATA_KEY_PLAYABLE.

Summary

Public constructors

Callback for the MediaLibrarySession.

Public methods

open LibraryResult
onGetChildren(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull parentId: String, page: Int, pageSize: Int, @Nullable params: MediaLibraryService.LibraryParams?)

Called to get children of given parent id.

open LibraryResult
onGetItem(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull mediaId: String)

Called to get an item.

open LibraryResult

Called to get the root information for browsing by a MediaBrowser.

open LibraryResult
onGetSearchResult(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull query: String, page: Int, pageSize: Int, @Nullable params: MediaLibraryService.LibraryParams?)

Called to get the search result.

open Int
onSearch(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull query: String, @Nullable params: MediaLibraryService.LibraryParams?)

Called when a controller requests search.

open Int
onSubscribe(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull parentId: String, @Nullable params: MediaLibraryService.LibraryParams?)

Called when a controller subscribes to the parent.

open Int
onUnsubscribe(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull parentId: String)

Called when a controller unsubscribes to the parent.

Inherited functions

Public constructors

<init>

MediaLibrarySessionCallback()

Callback for the MediaLibrarySession.

When you return LibraryResult with media items, items must have valid MediaMetadata#METADATA_KEY_MEDIA_ID and specify MediaMetadata#METADATA_KEY_BROWSABLE and MediaMetadata#METADATA_KEY_PLAYABLE.

Public methods

onGetChildren

@NonNull open fun onGetChildren(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull parentId: String, page: Int, pageSize: Int, @Nullable params: MediaLibraryService.LibraryParams?): LibraryResult

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

To allow getting the children, return the LibraryResult with the LibraryResult#RESULT_SUCCESS and the list of media item. Return an empty list for no children rather than using result code for error.

Parameters
session MediaLibraryService.MediaLibrarySession: the session for this event
controller MediaLibraryService.MediaLibrarySession: controller
parentId MediaLibraryService.MediaLibrarySession: non-empty parent id to get children
page MediaLibraryService.MediaLibrarySession: page number. Starts from 0.
pageSize MediaLibraryService.MediaLibrarySession: page size. Should be greater or equal to 1.
params MediaLibraryService.MediaLibrarySession: library params
Return
LibraryResult: a library result with a list of media item with the id. A runtime exception will be thrown if an invalid result is returned.

onGetItem

@NonNull open fun onGetItem(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull mediaId: String): LibraryResult

Called to get an item.

To allow getting the item, return the LibraryResult with the LibraryResult#RESULT_SUCCESS and the media item.

Parameters
session MediaLibraryService.MediaLibrarySession: the session for this event
controller MediaLibraryService.MediaLibrarySession: controller
mediaId MediaLibraryService.MediaLibrarySession: non-empty media id of the requested item
Return
LibraryResult: a library result with a media item with the id. A runtime exception will be thrown if an invalid result is returned.

onGetLibraryRoot

@NonNull open fun onGetLibraryRoot(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @Nullable params: MediaLibraryService.LibraryParams?): LibraryResult

Called to get the root information for browsing by a MediaBrowser.

To allow browsing media information, return the LibraryResult with the LibraryResult#RESULT_SUCCESS and the root media item with the valid media id. The media id must be included for the browser to get the children under it.

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

Parameters
session MediaLibraryService.MediaLibrarySession: the session for this event
controller MediaLibraryService.MediaLibrarySession: information of the controller requesting access to browse media.
params MediaLibraryService.MediaLibrarySession: An optional library params of service-specific arguments to send to the media library service when connecting and retrieving the root id for browsing, or null if none.
Return
LibraryResult: a library result with the root media item with the id. A runtime exception will be thrown if an invalid result is returned.

onGetSearchResult

@NonNull open fun onGetSearchResult(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull query: String, page: Int, pageSize: Int, @Nullable params: MediaLibraryService.LibraryParams?): LibraryResult

Called to get the search result.

To allow getting the search result, return the LibraryResult with the LibraryResult#RESULT_SUCCESS and the list of media item. Return an empty list for no search result rather than using result code for 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 MediaLibraryService.MediaLibrarySession: the session for this event
controller MediaLibraryService.MediaLibrarySession: controller
query MediaLibraryService.MediaLibrarySession: The non-empty search query which was previously sent through onSearch.
page MediaLibraryService.MediaLibrarySession: page number. Starts from 0.
pageSize MediaLibraryService.MediaLibrarySession: page size. Should be greater or equal to 1.
params MediaLibraryService.MediaLibrarySession: library params
Return
LibraryResult: a library result with a list of media item with the id. A runtime exception will be thrown if an invalid result is returned.

onSearch

open fun onSearch(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull query: String, @Nullable params: MediaLibraryService.LibraryParams?): Int

Called when a controller requests search.

Return immediately with the result of the attempt to search with the query. Notify the number of search result through notifySearchResultChanged(ControllerInfo, String, int, LibraryParams). MediaBrowser will ask the search result with the pagination later.

Parameters
session MediaLibraryService.MediaLibrarySession: the session for this event
controller MediaLibraryService.MediaLibrarySession: controller
query MediaLibraryService.MediaLibrarySession: The non-empty search query sent from the media browser. It contains keywords separated by space.
params MediaLibraryService.MediaLibrarySession: library params
Return
Int: result code

onSubscribe

open fun onSubscribe(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull parentId: String, @Nullable params: MediaLibraryService.LibraryParams?): Int

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, LibraryParams) when the parent is changed until it's unsubscribed.

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 MediaLibraryService.MediaLibrarySession: the session for this event
controller MediaLibraryService.MediaLibrarySession: controller
parentId MediaLibraryService.MediaLibrarySession: non-empty parent id
params MediaLibraryService.MediaLibrarySession: library params
Return
Int: result code

onUnsubscribe

open fun onUnsubscribe(@NonNull session: MediaLibraryService.MediaLibrarySession, @NonNull controller: MediaSession.ControllerInfo, @NonNull parentId: String): Int

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 MediaLibraryService.MediaLibrarySession: the session for this event
controller MediaLibraryService.MediaLibrarySession: controller
parentId MediaLibraryService.MediaLibrarySession: non-empty parent id
Return
Int: result code