MediaBrowser

Added in 1.0.0
Deprecated in 1.3.0

public class MediaBrowser extends MediaController


Browses media content offered by a MediaLibraryService.

Summary

Nested types

This class is deprecated.

androidx.media2 is deprecated.

public final class MediaBrowser.Builder

This class is deprecated.

androidx.media2 is deprecated.

Public methods

@NonNull ListenableFuture<LibraryResult>
getChildren(
    @NonNull String parentId,
    @IntRange(from = 0) int page,
    @IntRange(from = 1) int pageSize,
    @Nullable MediaLibraryService.LibraryParams params
)

Gets the list of children under the parent.

@NonNull ListenableFuture<LibraryResult>

Gets the media item with the given media id.

@NonNull ListenableFuture<LibraryResult>

Gets the library root.

@NonNull ListenableFuture<LibraryResult>
getSearchResult(
    @NonNull String query,
    @IntRange(from = 0) int page,
    @IntRange(from = 1) int pageSize,
    @Nullable MediaLibraryService.LibraryParams params
)

Gets the search result from the library service.

@NonNull ListenableFuture<LibraryResult>

Sends a search request to the library service.

@NonNull ListenableFuture<LibraryResult>

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

@NonNull ListenableFuture<LibraryResult>

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

Inherited methods

From java.io.Closeable
abstract void
From androidx.media2.session.MediaController
@NonNull ListenableFuture<SessionResult>
addPlaylistItem(@IntRange(from = 0) int index, @NonNull String mediaId)

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

@NonNull ListenableFuture<SessionResult>
adjustVolume(int direction, int flags)

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

void

Releases this object, and disconnects from the session.

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>

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

@Nullable 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.

@Nullable SessionToken

Returns the SessionToken of the connected session.

@Nullable 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.

@Nullable 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.

@Nullable List<MediaItem>

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

@Nullable 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.

@Nullable SessionPlayer.TrackInfo
getSelectedTrack(int trackType)

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

@Nullable 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.

@NonNull List<SessionPlayer.TrackInfo>

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

@NonNull 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.

@NonNull ListenableFuture<SessionResult>
movePlaylistItem(
    @IntRange(from = 0) int fromIndex,
    @IntRange(from = 0) int toIndex
)

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

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>
removePlaylistItem(@IntRange(from = 0) int index)

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

@NonNull ListenableFuture<SessionResult>
replacePlaylistItem(@IntRange(from = 0) int index, @NonNull String mediaId)

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

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>
seekTo(long position)

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

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>

Sends a custom command to the session

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>
setPlaybackSpeed(float playbackSpeed)

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

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>
setRating(@NonNull String mediaId, @NonNull Rating rating)

Requests that the connected MediaSession rates the media.

@NonNull ListenableFuture<SessionResult>
setRepeatMode(int repeatMode)

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

@NonNull ListenableFuture<SessionResult>
setShuffleMode(int shuffleMode)

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

@NonNull ListenableFuture<SessionResult>

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.

@NonNull ListenableFuture<SessionResult>
setVolumeTo(int value, int flags)

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

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>
skipToPlaylistItem(@IntRange(from = 0) int index)

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

@NonNull ListenableFuture<SessionResult>

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

@NonNull ListenableFuture<SessionResult>

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

Public methods

getChildren

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull ListenableFuture<LibraryResultgetChildren(
    @NonNull String parentId,
    @IntRange(from = 0) int page,
    @IntRange(from = 1) int pageSize,
    @Nullable MediaLibraryService.LibraryParams params
)

Gets the list of children under the parent.

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

Parameters
@NonNull String parentId

non-empty parent id for getting the children

@IntRange(from = 0) int page

page number to get the result. Starts from 0

@IntRange(from = 1) int pageSize

page size. Should be greater than or equal to 1

@Nullable MediaLibraryService.LibraryParams params

library params

See also
getMediaItems

getItem

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull ListenableFuture<LibraryResultgetItem(@NonNull String mediaId)

Gets the media item with the given media id.

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

Parameters
@NonNull String mediaId

non-empty media id for specifying the item

See also
getMediaItem

getLibraryRoot

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull ListenableFuture<LibraryResultgetLibraryRoot(@Nullable MediaLibraryService.LibraryParams params)

Gets the library root.

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

Parameters
@Nullable MediaLibraryService.LibraryParams params

library params getting root

See also
getMediaItem

getSearchResult

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull ListenableFuture<LibraryResultgetSearchResult(
    @NonNull String query,
    @IntRange(from = 0) int page,
    @IntRange(from = 1) int pageSize,
    @Nullable MediaLibraryService.LibraryParams params
)

Gets the search result from the library service.

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

Parameters
@NonNull String query

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

@IntRange(from = 0) int page

page number to get search result. Starts from 0

@IntRange(from = 1) int pageSize

page size. Should be greater or equal to 1

@Nullable MediaLibraryService.LibraryParams params

library params

See also
getMediaItems

search

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull ListenableFuture<LibraryResultsearch(
    @NonNull String query,
    @Nullable MediaLibraryService.LibraryParams params
)

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
@NonNull String query

non-empty search query

@Nullable MediaLibraryService.LibraryParams params

library params

subscribe

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull ListenableFuture<LibraryResultsubscribe(
    @NonNull String parentId,
    @Nullable MediaLibraryService.LibraryParams params
)

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
@NonNull String parentId

non-empty parent id

@Nullable MediaLibraryService.LibraryParams params

library params

unsubscribe

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull ListenableFuture<LibraryResultunsubscribe(@NonNull String parentId)

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
@NonNull String parentId

non-empty parent id