belongs to Maven artifact androidx.media2:media2:1.0.0-alpha01

MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback

public static class MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback
extends MediaSession2.SessionCallback

java.lang.Object
   ↳ androidx.media2.MediaSession2.SessionCallback
     ↳ androidx.media2.MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback


Callback for the MediaLibraryService2.MediaLibrarySession.

Summary

Public constructors

MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback()

Public methods

List<MediaItem2> onGetChildren(MediaLibraryService2.MediaLibrarySession session, MediaSession2.ControllerInfo controller, String parentId, int page, int pageSize, Bundle extras)

Called to get children of given parent id.

MediaItem2 onGetItem(MediaLibraryService2.MediaLibrarySession session, MediaSession2.ControllerInfo controller, String mediaId)

Called to get an item.

MediaLibraryService2.LibraryRoot onGetLibraryRoot(MediaLibraryService2.MediaLibrarySession session, MediaSession2.ControllerInfo controller, Bundle rootHints)

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

List<MediaItem2> onGetSearchResult(MediaLibraryService2.MediaLibrarySession session, MediaSession2.ControllerInfo controller, String query, int page, int pageSize, Bundle extras)

Called to get the search result.

void onSearch(MediaLibraryService2.MediaLibrarySession session, MediaSession2.ControllerInfo controller, String query, Bundle extras)

Called when a controller requests search.

void onSubscribe(MediaLibraryService2.MediaLibrarySession session, MediaSession2.ControllerInfo controller, String parentId, Bundle extras)

Called when a controller subscribes to the parent.

void onUnsubscribe(MediaLibraryService2.MediaLibrarySession session, MediaSession2.ControllerInfo controller, String parentId)

Called when a controller unsubscribes to the parent.

Inherited methods

Public constructors

MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback

public MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback ()

Public methods

onGetChildren

public List<MediaItem2> onGetChildren (MediaLibraryService2.MediaLibrarySession session, 
                MediaSession2.ControllerInfo controller, 
                String parentId, 
                int page, 
                int pageSize, 
                Bundle extras)

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 MediaSession2.ControllerInfo: controller

parentId String: parent id to get children

page int: number of page

pageSize int: size of the page

extras Bundle: extra bundle

Returns
List<MediaItem2> list of children. Can be null.

onGetItem

public MediaItem2 onGetItem (MediaLibraryService2.MediaLibrarySession session, 
                MediaSession2.ControllerInfo controller, 
                String mediaId)

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 MediaSession2.ControllerInfo: controller

mediaId String: item id to get media item.

Returns
MediaItem2 a media item. null for no result or error.

onGetLibraryRoot

public MediaLibraryService2.LibraryRoot onGetLibraryRoot (MediaLibraryService2.MediaLibrarySession session, 
                MediaSession2.ControllerInfo controller, 
                Bundle rootHints)

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 MediaSession2.ControllerInfo: information of the controller requesting access to browse media.

rootHints Bundle: 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.

Returns
MediaLibraryService2.LibraryRoot The MediaLibraryService2.LibraryRoot for accessing this app's content or null.

onGetSearchResult

public List<MediaItem2> onGetSearchResult (MediaLibraryService2.MediaLibrarySession session, 
                MediaSession2.ControllerInfo controller, 
                String query, 
                int page, 
                int pageSize, 
                Bundle extras)

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.

Parameters
session MediaLibraryService2.MediaLibrarySession: the session for this event

controller MediaSession2.ControllerInfo: controller

query String: The search query which was previously sent through onSearch(MediaLibrarySession, ControllerInfo, String, Bundle).

page int: page number. Starts from 1.

pageSize int: page size. Should be greater or equal to 1.

extras Bundle: The bundle of service-specific arguments sent from the media browser.

Returns
List<MediaItem2> search result. null for error.

onSearch

public void onSearch (MediaLibraryService2.MediaLibrarySession session, 
                MediaSession2.ControllerInfo controller, 
                String query, 
                Bundle extras)

Called when a controller requests search.

Parameters
session MediaLibraryService2.MediaLibrarySession: the session for this event

controller MediaSession2.ControllerInfo: controller

query String: The search query sent from the media browser. It contains keywords separated by space.

extras Bundle: The bundle of service-specific arguments sent from the media browser.

onSubscribe

public void onSubscribe (MediaLibraryService2.MediaLibrarySession session, 
                MediaSession2.ControllerInfo controller, 
                String parentId, 
                Bundle extras)

Called when a controller subscribes to the parent.

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

Parameters
session MediaLibraryService2.MediaLibrarySession: the session for this event

controller MediaSession2.ControllerInfo: controller

parentId String: parent id

extras Bundle: extra bundle

onUnsubscribe

public void onUnsubscribe (MediaLibraryService2.MediaLibrarySession session, 
                MediaSession2.ControllerInfo controller, 
                String parentId)

Called when a controller unsubscribes to the parent.

Parameters
session MediaLibraryService2.MediaLibrarySession: the session for this event

controller MediaSession2.ControllerInfo: controller

parentId String: parent id