Register now for Android Dev Summit 2019!

MediaBrowser

open class MediaBrowser : MediaController
kotlin.Any
   ↳ androidx.media2.session.MediaController
   ↳ androidx.media2.session.MediaBrowser

Browses media content offered by a MediaLibraryService.

Summary

Nested classes

open

Callback to listen events from MediaLibraryService.

Builder for MediaBrowser.

Public methods

open ListenableFuture<LibraryResult!>
getChildren(@NonNull parentId: String, page: Int, pageSize: Int, @Nullable params: MediaLibraryService.LibraryParams?)

Gets the list of children under the parent.

open ListenableFuture<LibraryResult!>
getItem(@NonNull mediaId: String)

Gets the media item with the given media id.

open ListenableFuture<LibraryResult!>

Gets the library root.

open ListenableFuture<LibraryResult!>
getSearchResult(@NonNull query: String, page: Int, pageSize: Int, @Nullable params: MediaLibraryService.LibraryParams?)

Gets the search result from lhe library service.

open ListenableFuture<LibraryResult!>
search(@NonNull query: String, @Nullable params: MediaLibraryService.LibraryParams?)

Sends a search request to the library service.

open ListenableFuture<LibraryResult!>
subscribe(@NonNull parentId: String, @Nullable params: MediaLibraryService.LibraryParams?)

Subscribes to a parent id for the change in its children.

open ListenableFuture<LibraryResult!>
unsubscribe(@NonNull parentId: String)

Unsubscribes for changes to the children of the parent, which was previously subscribed with subscribe(String, LibraryParams).

Inherited functions

Public methods

getChildren

@NonNull open fun getChildren(@NonNull parentId: String, page: Int, pageSize: Int, @Nullable params: MediaLibraryService.LibraryParams?): ListenableFuture<LibraryResult!>

Gets the list of children under the parent.

If it's successfully completed, LibraryResult#getMediaItems() will return the list of children.

Parameters
parentId String: non-empty parent id for getting the children
page String: page number to get the result. Starts from 0
pageSize String: page size. Should be greater or equal to 1
params String: library params

getItem

@NonNull open fun getItem(@NonNull mediaId: String): ListenableFuture<LibraryResult!>

Gets the media item with the given media id.

If it's successfully completed, LibraryResult#getMediaItem() will return the media item.

Parameters
mediaId String: non-empty media id for specifying the item

getLibraryRoot

@NonNull open fun getLibraryRoot(@Nullable params: MediaLibraryService.LibraryParams?): ListenableFuture<LibraryResult!>

Gets the library root.

If it's successfully completed, LibraryResult#getMediaItem() will return the library root.

Parameters
params MediaLibraryService.LibraryParams?: library params getting root

getSearchResult

@NonNull open fun getSearchResult(@NonNull query: String, page: Int, pageSize: Int, @Nullable params: MediaLibraryService.LibraryParams?): ListenableFuture<LibraryResult!>

Gets the search result from lhe library service.

If it's successfully completed, LibraryResult#getMediaItems() will return the search result.

Parameters
query String: non-empty search query that you've specified with search(String, LibraryParams).
page String: page number to get search result. Starts from 0
pageSize String: page size. Should be greater or equal to 1
params String: library params

search

@NonNull open fun search(@NonNull query: String, @Nullable params: MediaLibraryService.LibraryParams?): ListenableFuture<LibraryResult!>

Sends a search request to the library service.

Returned LibraryResult will only tell whether the attemp to search was successful. For getting the search result, waits for BrowserCallback#getSearchResult(String, int, int, LibraryParams) the search result and calls getSearchResult(String, int, int, LibraryParams)} for getting the result.

Parameters
query String: non-empty search query
params String: library params

subscribe

@NonNull open fun subscribe(@NonNull parentId: String, @Nullable params: MediaLibraryService.LibraryParams?): ListenableFuture<LibraryResult!>

Subscribes to a parent id for the change in its children. When there's a change, BrowserCallback#onChildrenChanged(MediaBrowser, String, int, LibraryParams) will be called with the library params. You should call getChildren(String, int, int, LibraryParams) to get the items under the parent.

Parameters
parentId String: non-empty parent id
params String: library params

unsubscribe

@NonNull open fun unsubscribe(@NonNull parentId: String): ListenableFuture<LibraryResult!>

Unsubscribes for changes to the children of the parent, which was previously subscribed with subscribe(String, LibraryParams).

This unsubscribes all previous subscription with the parent id, regardless of the library param that was previously sent to the library service.

Parameters
parentId String: non-empty parent id