MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback
public
static
class
MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback
extends MediaSession.SessionCallback
java.lang.Object | ||
↳ | androidx.media2.session.MediaSession.SessionCallback | |
↳ | androidx.media2.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback |
Callback for the MediaLibraryService.MediaLibrarySession
.
When you return 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
Public constructors | |
---|---|
MediaLibrarySessionCallback()
|
Inherited methods | |
---|---|
Public constructors
MediaLibrarySessionCallback
public MediaLibrarySessionCallback ()
Public methods
onGetChildren
public LibraryResult onGetChildren (MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, 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 LibraryResult
with the
LibraryResult.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 |
int : page number. Starts from 0 . |
pageSize |
int : page size. Should be greater or equal to 1 .Value is 1 or greater. |
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
public LibraryResult onGetItem (MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, String mediaId)
Called to get an item.
To allow getting the item, return the LibraryResult
with the
LibraryResult.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
public LibraryResult onGetLibraryRoot (MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, MediaLibraryService.LibraryParams params)
Called to get the root information for browsing by a MediaBrowser
.
To allow browsing media information, return the LibraryResult
with the
LibraryResult.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
public LibraryResult onGetSearchResult (MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, String query, int page, int pageSize, MediaLibraryService.LibraryParams params)
Called to get the search result.
To allow getting the search result, return the LibraryResult
with the
LibraryResult.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(MediaLibraryService.MediaLibrarySession, MediaSession.ControllerInfo, String, MediaLibraryService.LibraryParams)
, especially
when MediaBrowserCompat.search(String, Bundle, MediaBrowserCompat.SearchCallback)
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(MediaLibraryService.MediaLibrarySession, MediaSession.ControllerInfo, String, MediaLibraryService.LibraryParams) . |
page |
int : page number. Starts from 0 . |
pageSize |
int : page size. Should be greater or equal to 1 .Value is 1 or greater. |
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
public int onSearch (MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, 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.notifySearchResultChanged(ControllerInfo, String, int, LibraryParams)
.
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
public int onSubscribe (MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, 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.notifyChildrenChanged(ControllerInfo, String, int, LibraryParams)
when the parent is changed until it's
unsubscribed.
Interoperability: This will be called when
MediaBrowserCompat.subscribe(String, Bundle, MediaBrowserCompat.SubscriptionCallback)
is called.
However, this won't be called when MediaBrowser.subscribe(String, MediaLibraryService.LibraryParams)
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
public int onUnsubscribe (MediaLibraryService.MediaLibrarySession session, MediaSession.ControllerInfo controller, 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
MediaBrowserCompat.unsubscribe(String)
.
Parameters | |
---|---|
session |
MediaLibraryService.MediaLibrarySession : the session for this event |
controller |
MediaSession.ControllerInfo : controller |
parentId |
String : non-empty parent id |
Returns | |
---|---|
int |
result code |