MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback

Added in 1.0.0
Deprecated in 1.3.0

class MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback : MediaSession.SessionCallback


Callback for the MediaLibrarySession.

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

Summary

Public constructors

Public functions

LibraryResult
onGetChildren(
    session: MediaLibraryService.MediaLibrarySession,
    controller: MediaSession.ControllerInfo,
    parentId: String,
    page: @IntRange(from = 0) Int,
    pageSize: @IntRange(from = 1) Int,
    params: MediaLibraryService.LibraryParams?
)

Called to get children of given parent id.

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

Called to get an item.

LibraryResult

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

LibraryResult
onGetSearchResult(
    session: MediaLibraryService.MediaLibrarySession,
    controller: MediaSession.ControllerInfo,
    query: String,
    page: @IntRange(from = 0) Int,
    pageSize: @IntRange(from = 1) Int,
    params: MediaLibraryService.LibraryParams?
)

Called to get the search result.

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

Called when a controller requests search.

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

Called when a controller subscribes to the parent.

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

Called when a controller unsubscribes to the parent.

Inherited functions

From androidx.media2.session.MediaSession.SessionCallback
Int
onCommandRequest(
    session: MediaSession,
    controller: MediaSession.ControllerInfo,
    command: SessionCommand
)

Called when a controller sent a command which will be sent directly to one of the following:

SessionCommandGroup?

Called when a controller is created for this session.

MediaItem?
onCreateMediaItem(
    session: MediaSession,
    controller: MediaSession.ControllerInfo,
    mediaId: String
)

Called when a controller has sent a command with a MediaItem to add a new media item to this session.

SessionResult
onCustomCommand(
    session: MediaSession,
    controller: MediaSession.ControllerInfo,
    customCommand: SessionCommand,
    args: Bundle?
)

Called when a controller sent a custom command through sendCustomCommand.

Unit
onDisconnected(
    session: MediaSession,
    controller: MediaSession.ControllerInfo
)

Called when a controller is disconnected.

Int
onFastForward(
    session: MediaSession,
    controller: MediaSession.ControllerInfo
)

Called when a controller called fastForward.

Unit
onPostConnect(
    session: MediaSession,
    controller: MediaSession.ControllerInfo
)

Called immediately after a controller is connected.

Int

Called when a controller called rewind.

Int
onSetMediaUri(
    session: MediaSession,
    controller: MediaSession.ControllerInfo,
    uri: Uri,
    extras: Bundle?
)

Called when a controller requested to set the specific media item(s) represented by a URI through setMediaUri.

Int
onSetRating(
    session: MediaSession,
    controller: MediaSession.ControllerInfo,
    mediaId: String,
    rating: Rating
)

Called when a controller set rating of a media item through setRating.

Int
onSkipBackward(
    session: MediaSession,
    controller: MediaSession.ControllerInfo
)

Called when a controller called skipBackward.

Int
onSkipForward(
    session: MediaSession,
    controller: MediaSession.ControllerInfo
)

Called when a controller called skipForward.

Public constructors

MediaLibrarySessionCallback

Added in 1.0.0
Deprecated in 1.3.0
MediaLibrarySessionCallback()

Public functions

onGetChildren

Added in 1.0.0
Deprecated in 1.3.0
fun onGetChildren(
    session: MediaLibraryService.MediaLibrarySession,
    controller: MediaSession.ControllerInfo,
    parentId: String,
    page: @IntRange(from = 0) Int,
    pageSize: @IntRange(from = 1) Int,
    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 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: MediaSession.ControllerInfo

controller

parentId: String

non-empty parent id to get children

page: @IntRange(from = 0) Int

page number. Starts from 0.

pageSize: @IntRange(from = 1) Int

page size. Should be greater or equal to 1.

params: MediaLibraryService.LibraryParams?

library params

Returns
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

Added in 1.0.0
Deprecated in 1.3.0
fun onGetItem(
    session: MediaLibraryService.MediaLibrarySession,
    controller: MediaSession.ControllerInfo,
    mediaId: String
): LibraryResult

Called to get an item.

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

Parameters
session: MediaLibraryService.MediaLibrarySession

the session for this event

controller: MediaSession.ControllerInfo

controller

mediaId: String

non-empty media id of the requested item

Returns
LibraryResult

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

onGetLibraryRoot

Added in 1.0.0
Deprecated in 1.3.0
fun onGetLibraryRoot(
    session: MediaLibraryService.MediaLibrarySession,
    controller: MediaSession.ControllerInfo,
    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 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: MediaSession.ControllerInfo

information of the controller requesting access to browse media.

params: MediaLibraryService.LibraryParams?

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

Added in 1.0.0
Deprecated in 1.3.0
fun onGetSearchResult(
    session: MediaLibraryService.MediaLibrarySession,
    controller: MediaSession.ControllerInfo,
    query: String,
    page: @IntRange(from = 0) Int,
    pageSize: @IntRange(from = 1) Int,
    params: MediaLibraryService.LibraryParams?
): LibraryResult

Called to get the search result.

To allow getting the search result, return the LibraryResult with the 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 search is used.

Parameters
session: MediaLibraryService.MediaLibrarySession

the session for this event

controller: MediaSession.ControllerInfo

controller

query: String

The non-empty search query which was previously sent through onSearch.

page: @IntRange(from = 0) Int

page number. Starts from 0.

pageSize: @IntRange(from = 1) Int

page size. Should be greater or equal to 1.

params: MediaLibraryService.LibraryParams?

library params

Returns
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

Added in 1.0.0
Deprecated in 1.3.0
fun onSearch(
    session: MediaLibraryService.MediaLibrarySession,
    controller: MediaSession.ControllerInfo,
    query: String,
    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. MediaBrowser will ask the search result with the pagination later.

Parameters
session: MediaLibraryService.MediaLibrarySession

the session for this event

controller: MediaSession.ControllerInfo

controller

query: String

The non-empty search query sent from the media browser. It contains keywords separated by space.

params: MediaLibraryService.LibraryParams?

library params

Returns
Int

result code

onSubscribe

Added in 1.0.0
Deprecated in 1.3.0
fun onSubscribe(
    session: MediaLibraryService.MediaLibrarySession,
    controller: MediaSession.ControllerInfo,
    parentId: String,
    params: MediaLibraryService.LibraryParams?
): Int

Called when a controller subscribes to the parent.

It's your responsibility to keep subscriptions by your own and call notifyChildrenChanged 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 subscribe is called.

Parameters
session: MediaLibraryService.MediaLibrarySession

the session for this event

controller: MediaSession.ControllerInfo

controller

parentId: String

non-empty parent id

params: MediaLibraryService.LibraryParams?

library params

Returns
Int

result code

onUnsubscribe

Added in 1.0.0
Deprecated in 1.3.0
fun onUnsubscribe(
    session: MediaLibraryService.MediaLibrarySession,
    controller: MediaSession.ControllerInfo,
    parentId: String
): Int

Called when a controller unsubscribes to the parent.

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

Parameters
session: MediaLibraryService.MediaLibrarySession

the session for this event

controller: MediaSession.ControllerInfo

controller

parentId: String

non-empty parent id

Returns
Int

result code