belongs to Maven artifact androidx.media2:media2:1.0.0-alpha01

MediaBrowser2

public class MediaBrowser2
extends MediaController2

java.lang.Object
   ↳ androidx.media2.MediaController2
     ↳ androidx.media2.MediaBrowser2


Browses media content offered by a MediaLibraryService2.

Summary

Nested classes

class MediaBrowser2.BrowserCallback

Callback to listen events from MediaLibraryService2

Public constructors

MediaBrowser2(Context context, SessionToken2 token, Executor executor, MediaBrowser2.BrowserCallback callback)

Public methods

void getChildren(String parentId, int page, int pageSize, Bundle extras)

Get list of children under the parent.

void getItem(String mediaId)

Get the media item with the given media id.

void getLibraryRoot(Bundle extras)

Get the library root.

void getSearchResult(String query, int page, int pageSize, Bundle extras)

Get the search result from lhe library service.

void search(String query, Bundle extras)

Send a search request to the library service.

void subscribe(String parentId, Bundle extras)

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

void unsubscribe(String parentId)

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

Inherited methods

Public constructors

MediaBrowser2

public MediaBrowser2 (Context context, 
                SessionToken2 token, 
                Executor executor, 
                MediaBrowser2.BrowserCallback callback)

Parameters
context Context

token SessionToken2

executor Executor

callback MediaBrowser2.BrowserCallback

Public methods

getChildren

public void getChildren (String parentId, 
                int page, 
                int pageSize, 
                Bundle extras)

Get list of children under the parent. Result would be sent back asynchronously with the MediaBrowser2.BrowserCallback.onGetChildrenDone(MediaBrowser2, String, int, int, List, Bundle).

Parameters
parentId String: parent id for getting the children.

page int: page number to get the result. Starts from 1

pageSize int: page size. Should be greater or equal to 1

extras Bundle: extra bundle

getItem

public void getItem (String mediaId)

Get the media item with the given media id. Result would be sent back asynchronously with the MediaBrowser2.BrowserCallback.onGetItemDone(MediaBrowser2, String, MediaItem2).

Parameters
mediaId String: media id for specifying the item

getLibraryRoot

public void getLibraryRoot (Bundle extras)

Get the library root. Result would be sent back asynchronously with the MediaBrowser2.BrowserCallback.onGetLibraryRootDone(MediaBrowser2, Bundle, String, Bundle).

Parameters
extras Bundle: extras for getting root

getSearchResult

public void getSearchResult (String query, 
                int page, 
                int pageSize, 
                Bundle extras)

Get the search result from lhe library service. Result would be sent back asynchronously with the MediaBrowser2.BrowserCallback.onGetSearchResultDone(MediaBrowser2, String, int, int, List, Bundle).

Parameters
query String: search query that you've specified with search(String, Bundle)

page int: page number to get search result. Starts from 1

pageSize int: page size. Should be greater or equal to 1

extras Bundle: extra bundle

search

public void search (String query, 
                Bundle extras)

Send a search request to the library service. When the search result is changed, MediaBrowser2.BrowserCallback.onSearchResultChanged(MediaBrowser2, String, int, Bundle) will be called. You should call getSearchResult(String, int, int, Bundle) to get the actual search result.

Parameters
query String: search query. Should not be an empty string.

extras Bundle: extra bundle

subscribe

public void subscribe (String parentId, 
                Bundle extras)

Subscribe to a parent id for the change in its children. When there's a change, MediaBrowser2.BrowserCallback.onChildrenChanged(MediaBrowser2, String, int, Bundle) will be called with the bundle that you've specified. You should call getChildren(String, int, int, Bundle) to get the actual contents for the parent.

Parameters
parentId String: parent id

extras Bundle: extra bundle

unsubscribe

public void unsubscribe (String parentId)

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

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

Parameters
parentId String: parent id