public interface

MediaLibraryService.MediaLibrarySession.Callback

implements MediaSession.Callback

 androidx.media3.session.MediaLibraryService.MediaLibrarySession.Callback

Overview

An extended MediaSession.Callback for the MediaLibraryService.MediaLibrarySession.

When you return LibraryResult with media items, each item must have valid MediaItem.mediaId and specify MediaMetadata.isBrowsable and MediaMetadata.isPlayable in its MediaItem.mediaMetadata.

Summary

Methods
public <any>onGetChildren(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String parentId, int page, int pageSize, MediaLibraryService.LibraryParams params)

Called when a MediaBrowser requests the child media items of the given parent id by MediaBrowser.

public <any>onGetItem(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String mediaId)

Called when a MediaBrowser requests a MediaItem by MediaBrowser.getItem(String).

public <any>onGetLibraryRoot(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, MediaLibraryService.LibraryParams params)

Called when a MediaBrowser requests the root MediaItem by MediaBrowser.

public <any>onGetSearchResult(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String query, int page, int pageSize, MediaLibraryService.LibraryParams params)

Called when a MediaBrowser requests a search result with MediaBrowser.

public <any>onSearch(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String query, MediaLibraryService.LibraryParams params)

Called when a MediaBrowser requests a search with MediaBrowser.

public <any>onSubscribe(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String parentId, MediaLibraryService.LibraryParams params)

Called when a MediaBrowser subscribes to the given parent id by MediaBrowser.

public <any>onUnsubscribe(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String parentId)

Called when a MediaBrowser unsubscribes from the given parent ID by MediaBrowser.unsubscribe(String).

Methods

Called when a MediaBrowser requests the root MediaItem by MediaBrowser.

Return a to send a LibraryResult back to the browser asynchronously. You can also return a LibraryResult directly by using Guava's .

The LibraryResult.params may differ from the given params if the session can't provide a root that matches with the params.

To allow browsing the media library, return a LibraryResult with LibraryResult.RESULT_SUCCESS and a root MediaItem with a valid MediaItem.mediaId. The media id is required for the browser to get the children under the root.

Interoperability: If this callback is called because a legacy android.support.v4.media.MediaBrowserCompat has requested a androidx.media.MediaBrowserServiceCompat.BrowserRoot, then the main thread may be blocked until the returned future is done. If your service may be queried by a legacy android.support.v4.media.MediaBrowserCompat, you should ensure that the future completes quickly to avoid blocking the main thread for a long period of time.

Parameters:

session: The session for this event.
browser: The browser information.
params: The optional parameters passed by the browser.

Returns:

A pending result that will be resolved with a root media item.

See also: SessionCommand.COMMAND_CODE_LIBRARY_GET_LIBRARY_ROOT

public <any> onGetItem(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String mediaId)

Called when a MediaBrowser requests a MediaItem by MediaBrowser.getItem(String).

Return a to send a LibraryResult back to the browser asynchronously. You can also return a LibraryResult directly by using Guava's .

To allow getting the item, return a LibraryResult with LibraryResult.RESULT_SUCCESS and a MediaItem with a valid MediaItem.mediaId.

Parameters:

session: The session for this event.
browser: The browser information.
mediaId: The non-empty media id of the requested item.

Returns:

A pending result that will be resolved with a media item.

See also: SessionCommand.COMMAND_CODE_LIBRARY_GET_ITEM

public <any> onGetChildren(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String parentId, int page, int pageSize, MediaLibraryService.LibraryParams params)

Called when a MediaBrowser requests the child media items of the given parent id by MediaBrowser.

Return a to send a LibraryResult back to the browser asynchronously. You can also return a LibraryResult directly by using Guava's .

The LibraryResult.params should be the same as the given params.

To allow getting the children, return a LibraryResult with LibraryResult.RESULT_SUCCESS and a list of media items. Return an empty list for no children rather than using error codes.

Parameters:

session: The session for this event
browser: The browser information.
parentId: The non-empty parent id.
page: The page number to get the paginated result starting from 0.
pageSize: The page size to get the paginated result. Will be greater than 0.
params: The optional parameters passed by the browser.

Returns:

A pending result that will be resolved with a list of media items.

See also: SessionCommand.COMMAND_CODE_LIBRARY_GET_CHILDREN

public <any> onSubscribe(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String parentId, MediaLibraryService.LibraryParams params)

Called when a MediaBrowser subscribes to the given parent id by MediaBrowser.

See MediaLibraryService.MediaLibrarySession.getSubscribedControllers(String) also.

By default, the library calls MediaLibraryService.MediaLibrarySession.Callback for the parentId that the browser requests to subscribe to. If onGetItem returns LibraryResult.RESULT_SUCCESS with a browsable item, the subscription is accepted and MediaLibraryService.MediaLibrarySession is immediately called with an itemCount of MAX_VALUE. In all other cases, the subscription is rejected and a result value different to LibraryResult.RESULT_SUCCESS is returned from this method.

To implement a different behavior, an app can safely override this method without calling super. Return a result code LibraryResult.RESULT_SUCCESS to accept the subscription, or return a result different to LibraryResult.RESULT_SUCCESS to prevent controllers from subscribing.

Return a to send a LibraryResult back to the browser asynchronously. You can also return a LibraryResult directly by using Guava's .

The LibraryResult.params returned to the caller should be the same as the params passed into this method.

Interoperability: This will be called by android.support.v4.media.MediaBrowserCompat.subscribe(), but won't be called by .

Parameters:

session: The session for this event.
browser: The browser information.
parentId: The non-empty parent id.
params: The optional parameters passed by the browser.

Returns:

A pending result that will be resolved with a result code.

See also: SessionCommand.COMMAND_CODE_LIBRARY_SUBSCRIBE

public <any> onUnsubscribe(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String parentId)

Called when a MediaBrowser unsubscribes from the given parent ID by MediaBrowser.unsubscribe(String).

Return a to send a LibraryResult back to the browser asynchronously. You can also return a LibraryResult directly by using Guava's .

Apps normally don't need to implement this method, because the library maintains the subscribed controllers internally and an app can use MediaLibraryService.MediaLibrarySession.getSubscribedControllers(String) to get subscribed controllers for which to call MediaLibraryService.MediaLibrarySession.notifyChildrenChanged(MediaSession.ControllerInfo, String, int, MediaLibraryService.LibraryParams).

Interoperability: This will be called by android.support.v4.media.MediaBrowserCompat.unsubscribe(), but won't be called by .

Parameters:

session: The session for this event.
browser: The browser information.
parentId: The non-empty parent id.

Returns:

A pending result that will be resolved with a result code.

See also: SessionCommand.COMMAND_CODE_LIBRARY_UNSUBSCRIBE

public <any> onSearch(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String query, MediaLibraryService.LibraryParams params)

Called when a MediaBrowser requests a search with MediaBrowser.

Return a to send a LibraryResult back to the browser asynchronously. You can also return a LibraryResult directly by using Guava's .

The LibraryResult.params should be the same as the given params.

Return LibraryResult with a result code for the search and notify the number of search result (media items) through MediaLibraryService.MediaLibrarySession.Callback. MediaBrowser will ask the search result afterwards through MediaLibraryService.MediaLibrarySession.Callback.

Parameters:

session: The session for this event.
browser: The browser information.
query: The non-empty search query.
params: The optional parameters passed by the browser.

Returns:

A pending result that will be resolved with a result code.

See also: SessionCommand.COMMAND_CODE_LIBRARY_SEARCH

public <any> onGetSearchResult(MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo browser, java.lang.String query, int page, int pageSize, MediaLibraryService.LibraryParams params)

Called when a MediaBrowser requests a search result with MediaBrowser.

Return a to send a LibraryResult back to the browser asynchronously. You can also return a LibraryResult directly by using Guava's .

The LibraryResult.params should be the same as the given params.

To allow getting the search result, return a LibraryResult with LibraryResult.RESULT_SUCCESS and a list of media items. Return an empty list for no children rather than using error codes.

Typically, the query is requested through MediaLibraryService.MediaLibrarySession.Callback before, but it may not especially when android.support.v4.media.MediaBrowserCompat.search() is used.

Parameters:

session: The session for this event.
browser: The browser information.
query: The non-empty search query.
page: The page number to get the paginated result starting from 0.
pageSize: The page size to get the paginated result. Will be greater than 0.
params: The optional parameters passed by the browser.

Returns:

A pending result that will be resolved with a list of media items.

See also: SessionCommand.COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT