MediaBrowser

Added in 1.0.0
Deprecated in 1.3.0

class MediaBrowser : MediaController


Browses media content offered by a MediaLibraryService.

Summary

Nested types

This class is deprecated.

androidx.media2 is deprecated.

This class is deprecated.

androidx.media2 is deprecated.

Public functions

ListenableFuture<LibraryResult!>
getChildren(
    parentId: String,
    page: @IntRange(from = 0) Int,
    pageSize: @IntRange(from = 1) Int,
    params: MediaLibraryService.LibraryParams?
)

Gets the list of children under the parent.

ListenableFuture<LibraryResult!>
getItem(mediaId: String)

Gets the media item with the given media id.

ListenableFuture<LibraryResult!>

Gets the library root.

ListenableFuture<LibraryResult!>
getSearchResult(
    query: String,
    page: @IntRange(from = 0) Int,
    pageSize: @IntRange(from = 1) Int,
    params: MediaLibraryService.LibraryParams?
)

Gets the search result from the library service.

ListenableFuture<LibraryResult!>

Sends a search request to the library service.

ListenableFuture<LibraryResult!>

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

ListenableFuture<LibraryResult!>
unsubscribe(parentId: String)

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

Inherited functions

From java.io.Closeable
abstract Unit
From androidx.media2.session.MediaController
ListenableFuture<SessionResult!>
addPlaylistItem(index: @IntRange(from = 0) Int, mediaId: String)

Requests that the SessionPlayer associated with the connected MediaSession adds the media item to the playlist at the index with the media ID.

ListenableFuture<SessionResult!>
adjustVolume(direction: Int, flags: Int)

Requests that the connected MediaSession adjusts the volume of the output that is playing on.

Unit

Releases this object, and disconnects from the session.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession deselects the TrackInfo for the current media item.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession to fast forward playback.

SessionCommandGroup?

Gets the cached allowed commands from onAllowedCommandsChanged.

Long

Gets the position for how much has been buffered of the SessionPlayer associated with the connected MediaSession, or UNKNOWN_TIME if unknown or not connected.

Int

Gets the current buffering state of the SessionPlayer associated with the connected MediaSession.

SessionToken?

Returns the SessionToken of the connected session.

MediaItem?

Gets the current media item of the SessionPlayer associated with the connected MediaSession.

Int

Gets the current item index in the playlist of the SessionPlayer associated with the connected MediaSession.

Long

Gets the playback position of the SessionPlayer associated with the connected MediaSession.

Long

Gets the duration of the current media item, or UNKNOWN_TIME if unknown or not connected.

Int

Gets the next item index in the playlist of the SessionPlayer associated with the connected MediaSession.

MediaController.PlaybackInfo?

Get the current playback info for this session.

Float

Gets the playback speed to be used by the of the SessionPlayer associated with the connected MediaSession when playing.

Int

Gets the state of the SessionPlayer associated with the connected MediaSession.

(Mutable)List<MediaItem!>?

Gets the playlist of the SessionPlayer associated with the connected MediaSession.

MediaMetadata?

Gets the playlist metadata of the SessionPlayer associated with the connected MediaSession.

Int

Gets the previous item index in the playlist of the SessionPlayer associated with the connected MediaSession.

Int

Gets the repeat mode of the SessionPlayer associated with the connected MediaSession.

SessionPlayer.TrackInfo?
getSelectedTrack(trackType: Int)

Gets the currently selected track for the given track type of the SessionPlayer associated with the connected MediaSession.

PendingIntent?

Gets an intent for launching UI associated with this session if one exists.

Int

Gets the shuffle mode of the SessionPlayer associated with the connected MediaSession.

(Mutable)List<SessionPlayer.TrackInfo!>

Gets the full list of selected and unselected tracks that the media contains of the SessionPlayer associated with the connected MediaSession.

VideoSize

Gets the video size of the SessionPlayer associated with the connected MediaSession.

Boolean

Returns whether this class is connected to active MediaSession or not.

ListenableFuture<SessionResult!>
movePlaylistItem(
    fromIndex: @IntRange(from = 0) Int,
    toIndex: @IntRange(from = 0) Int
)

Requests that the SessionPlayer associated with the connected MediaSession moves the media item at fromIdx to toIdx in the playlist.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession pauses playback.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession starts or resumes playback.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession prepares the media items for playback.

ListenableFuture<SessionResult!>
removePlaylistItem(index: @IntRange(from = 0) Int)

Requests that the SessionPlayer associated with the connected MediaSession removes the media item at index in the playlist.

ListenableFuture<SessionResult!>
replacePlaylistItem(index: @IntRange(from = 0) Int, mediaId: String)

Requests that the SessionPlayer associated with the connected MediaSession replaces the media item at index in the playlist with the media ID.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession to rewind playback.

ListenableFuture<SessionResult!>
seekTo(position: Long)

Requests that the SessionPlayer associated with the connected MediaSession seeks to the specified position.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession selects the TrackInfo for the current media item.

ListenableFuture<SessionResult!>

Sends a custom command to the session

ListenableFuture<SessionResult!>
setMediaItem(mediaId: String)

Requests that the SessionPlayer associated with the connected MediaSession sets a MediaItem for playback.

ListenableFuture<SessionResult!>
setMediaUri(uri: Uri, extras: Bundle?)

Requests that the connected MediaSession sets a specific Uri for playback.

ListenableFuture<SessionResult!>
setPlaybackSpeed(playbackSpeed: Float)

Requests that the SessionPlayer associated with the connected MediaSession sets the playback speed.

ListenableFuture<SessionResult!>
setPlaylist(list: (Mutable)List<String!>, metadata: MediaMetadata?)

Requests that the SessionPlayer associated with the connected MediaSession sets the playlist with the list of media IDs.

ListenableFuture<SessionResult!>
setRating(mediaId: String, rating: Rating)

Requests that the connected MediaSession rates the media.

ListenableFuture<SessionResult!>
setRepeatMode(repeatMode: Int)

Requests that the SessionPlayer associated with the connected MediaSession sets the repeat mode.

ListenableFuture<SessionResult!>
setShuffleMode(shuffleMode: Int)

Requests that the SessionPlayer associated with the connected MediaSession sets the shuffle mode.

ListenableFuture<SessionResult!>
setSurface(surface: Surface?)

Requests that the SessionPlayer associated with the connected MediaSession sets the Surface to be used as the sink for the video portion of the media.

ListenableFuture<SessionResult!>
setVolumeTo(value: Int, flags: Int)

Requests that the connected MediaSession sets the volume of the output that is playing on.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession skips forward within the current media item.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession skips backward within the current media item.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession skips to the next item in the playlist.

ListenableFuture<SessionResult!>
skipToPlaylistItem(index: @IntRange(from = 0) Int)

Requests that the SessionPlayer associated with the connected MediaSession skips to the item in the playlist at the index.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession skips to the previous item in the playlist.

ListenableFuture<SessionResult!>

Requests that the SessionPlayer associated with the connected MediaSession updates the playlist metadata while keeping the playlist as-is.

Public functions

getChildren

Added in 1.0.0
Deprecated in 1.3.0
fun getChildren(
    parentId: String,
    page: @IntRange(from = 0) Int,
    pageSize: @IntRange(from = 1) Int,
    params: MediaLibraryService.LibraryParams?
): ListenableFuture<LibraryResult!>

Gets the list of children under the parent.

If it's successfully completed, getMediaItems will return the list of children.

Parameters
parentId: String

non-empty parent id for getting the children

page: @IntRange(from = 0) Int

page number to get the result. Starts from 0

pageSize: @IntRange(from = 1) Int

page size. Should be greater than or equal to 1

params: MediaLibraryService.LibraryParams?

library params

See also
getMediaItems

getItem

Added in 1.0.0
Deprecated in 1.3.0
fun getItem(mediaId: String): ListenableFuture<LibraryResult!>

Gets the media item with the given media id.

If it's successfully completed, getMediaItem will return the media item.

Parameters
mediaId: String

non-empty media id for specifying the item

See also
getMediaItem

getLibraryRoot

Added in 1.0.0
Deprecated in 1.3.0
fun getLibraryRoot(params: MediaLibraryService.LibraryParams?): ListenableFuture<LibraryResult!>

Gets the library root.

If it's successfully completed, getMediaItem will return the library root.

Parameters
params: MediaLibraryService.LibraryParams?

library params getting root

See also
getMediaItem

getSearchResult

Added in 1.0.0
Deprecated in 1.3.0
fun getSearchResult(
    query: String,
    page: @IntRange(from = 0) Int,
    pageSize: @IntRange(from = 1) Int,
    params: MediaLibraryService.LibraryParams?
): ListenableFuture<LibraryResult!>

Gets the search result from the library service.

If it's successfully completed, getMediaItems will return the search result.

Parameters
query: String

non-empty search query that you've specified with search.

page: @IntRange(from = 0) Int

page number to get search result. Starts from 0

pageSize: @IntRange(from = 1) Int

page size. Should be greater or equal to 1

params: MediaLibraryService.LibraryParams?

library params

See also
getMediaItems

search

Added in 1.0.0
Deprecated in 1.3.0
fun search(query: String, 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 onSearchResultChanged being called and call getSearchResult} for getting the result.

Parameters
query: String

non-empty search query

params: MediaLibraryService.LibraryParams?

library params

subscribe

Added in 1.0.0
Deprecated in 1.3.0
fun subscribe(parentId: String, params: MediaLibraryService.LibraryParams?): ListenableFuture<LibraryResult!>

Subscribes to a parent id for the change in its children. When there's a change, onChildrenChanged will be called with the library params. You should call getChildren to get the items under the parent.

Parameters
parentId: String

non-empty parent id

params: MediaLibraryService.LibraryParams?

library params

unsubscribe

Added in 1.0.0
Deprecated in 1.3.0
fun unsubscribe(parentId: String): ListenableFuture<LibraryResult!>

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

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