Google is committed to advancing racial equity for Black communities. See how.

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, @IntRange(0) page: Int, @IntRange(1) 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, @IntRange(0) page: Int, @IntRange(1) pageSize: Int, @Nullable params: MediaLibraryService.LibraryParams?)

Gets the search result from the 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,
    @IntRange(0) page: Int,
    @IntRange(1) 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 Int: page number to get the result. Starts from 0
pageSize Int: page size. Should be greater than or equal to 1
params MediaLibraryService.LibraryParams?: 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,
    @IntRange(0) page: Int,
    @IntRange(1) pageSize: Int,
    @Nullable params: MediaLibraryService.LibraryParams?
): ListenableFuture<LibraryResult!>

Gets the search result from the 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 Int: page number to get search result. Starts from 0
pageSize Int: page size. Should be greater or equal to 1
params MediaLibraryService.LibraryParams?: library params
@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 attempt to search was successful. For getting the search result, wait for BrowserCallback#onSearchResultChanged(MediaBrowser, String, int, LibraryParams) being called and call getSearchResult(String, int, int, LibraryParams)} for getting the result.

Parameters
query String: non-empty search query
params MediaLibraryService.LibraryParams?: 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 MediaLibraryService.LibraryParams?: 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 subscriptions with the parent id, regardless of the library param that was previously sent to the library service.

Parameters
parentId String: non-empty parent id