public class

MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback

extends MediaSession.SessionCallback

 java.lang.Object

androidx.media2.MediaSession.SessionCallback

↳androidx.media2.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback

Overview

Callback for the MediaLibraryService.MediaLibrarySession.

When you return MediaLibraryService.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

Constructors
publicMediaLibrarySessionCallback()

Methods
public MediaLibraryService.LibraryResultonGetChildren(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String parentId, int page, int pageSize, MediaLibraryService.LibraryParams params)

Called to get children of given parent id.

public MediaLibraryService.LibraryResultonGetItem(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String mediaId)

Called to get an item.

public MediaLibraryService.LibraryResultonGetLibraryRoot(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, MediaLibraryService.LibraryParams params)

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

public MediaLibraryService.LibraryResultonGetSearchResult(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String query, int page, int pageSize, MediaLibraryService.LibraryParams params)

Called to get the search result.

public intonSearch(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String query, MediaLibraryService.LibraryParams params)

Called when a controller requests search.

public intonSubscribe(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String parentId, MediaLibraryService.LibraryParams params)

Called when a controller subscribes to the parent.

public intonUnsubscribe(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String parentId)

Called when a controller unsubscribes to the parent.

from MediaSession.SessionCallbackonCommandRequest, onConnect, onCreateMediaItem, onCustomCommand, onDisconnected, onFastForward, onPlayFromMediaId, onPlayFromSearch, onPlayFromUri, onPrepareFromMediaId, onPrepareFromSearch, onPrepareFromUri, onRewind, onSetRating, onSkipBackward, onSkipForward
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public MediaLibrarySessionCallback()

Methods

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

To allow browsing media information, return the MediaLibraryService.LibraryResult with the RESULT_CODE_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: the session for this event
controller: information of the controller requesting access to browse media.
params: 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.

Returns:

a library result with the root media item with the id. A runtime exception will be thrown if an invalid result is returned.

See also: SessionCommand.COMMAND_CODE_LIBRARY_GET_LIBRARY_ROOT, MediaMetadata.METADATA_KEY_MEDIA_ID, MediaLibraryService.LibraryParams

public MediaLibraryService.LibraryResult onGetItem(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String mediaId)

Called to get an item.

To allow getting the item, return the MediaLibraryService.LibraryResult with the RESULT_CODE_SUCCESS and the media item.

Parameters:

session: the session for this event
controller: controller
mediaId: non-empty media id of the requested item

Returns:

a library result with a media item with the id. A runtime exception will be thrown if an invalid result is returned.

See also: SessionCommand.COMMAND_CODE_LIBRARY_GET_ITEM

public MediaLibraryService.LibraryResult onGetChildren(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String parentId, int page, int pageSize, MediaLibraryService.LibraryParams params)

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

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

Parameters:

session: the session for this event
controller: controller
parentId: non-empty parent id to get children
page: page number. Starts from 0.
pageSize: page size. Should be greater or equal to 1.
params: library params

Returns:

a library result with a list of media item with the id. A runtime exception will be thrown if an invalid result is returned.

See also: SessionCommand.COMMAND_CODE_LIBRARY_GET_CHILDREN, MediaLibraryService.LibraryParams

public int onSubscribe(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String parentId, MediaLibraryService.LibraryParams params)

Called when a controller subscribes to the parent.

It's your responsibility to keep subscriptions by your own and call MediaLibraryService.MediaLibrarySession when the parent is changed until it's unsubscribed.

Interoperability: This will be called when subscribe is called. However, this won't be called when MediaBrowser.subscribe(String, MediaLibraryService.LibraryParams) is called.

Parameters:

session: the session for this event
controller: controller
parentId: non-empty parent id
params: library params

Returns:

result code

See also: SessionCommand.COMMAND_CODE_LIBRARY_SUBSCRIBE, MediaLibraryService.LibraryParams

public int onUnsubscribe(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String parentId)

Called when a controller unsubscribes to the parent.

Interoperability: This wouldn't be called if MediaBrowser.unsubscribe(String) is called while works well with unsubscribe.

Parameters:

session: the session for this event
controller: controller
parentId: non-empty parent id

Returns:

result code

See also: SessionCommand.COMMAND_CODE_LIBRARY_UNSUBSCRIBE

public int onSearch(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String query, MediaLibraryService.LibraryParams params)

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 MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback. MediaBrowser will ask the search result with the pagination later.

Parameters:

session: the session for this event
controller: controller
query: The non-empty search query sent from the media browser. It contains keywords separated by space.
params: library params

Returns:

result code

See also: SessionCommand.COMMAND_CODE_LIBRARY_SEARCH, MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback, MediaLibraryService.LibraryParams

public MediaLibraryService.LibraryResult onGetSearchResult(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, java.lang.String query, int page, int pageSize, MediaLibraryService.LibraryParams params)

Called to get the search result.

To allow getting the search result, return the MediaLibraryService.LibraryResult with the RESULT_CODE_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 MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback.onSearch(MediaLibraryService.MediaLibrarySession, MediaSession.ControllerInfo, String, MediaLibraryService.LibraryParams), especially when search is used.

Parameters:

session: the session for this event
controller: controller
query: The non-empty search query which was previously sent through MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback.onSearch(MediaLibraryService.MediaLibrarySession, MediaSession.ControllerInfo, String, MediaLibraryService.LibraryParams).
page: page number. Starts from 0.
pageSize: page size. Should be greater or equal to 1.
params: library params

Returns:

a library result with a list of media item with the id. A runtime exception will be thrown if an invalid result is returned.

See also: SessionCommand.COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT, MediaLibraryService.LibraryParams