public interface

MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback

implements MediaSession.SessionCallback

 androidx.media3.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback

Overview

An extended for the MediaLibraryService.MediaLibrarySession.

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

Summary

Methods
public MediaSession.ConnectionResultonConnect(MediaSession session, MediaSession.ControllerInfo controller)

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 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.

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.

It's your responsibility to keep subscriptions and call MediaLibraryService.MediaLibrarySession when the children of the parent are changed until it's unsubscribed.

Interoperability: This will be called by 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 .

Interoperability: This will be called by 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.MediaLibrarySessionCallback. MediaBrowser will ask the search result afterwards through MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback.

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.MediaLibrarySessionCallback before, but it may not especially when 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