Stay organized with collections Save and categorize content based on your preferences.

MediaBrowser

public final class MediaBrowser extends MediaController


Browses media content offered by a MediaLibraryService in addition to the functions.

Summary

Nested types

public final class MediaBrowser.Builder

A builder for MediaBrowser.

public interface MediaBrowser.Listener extends MediaController.Listener

A listener for events from MediaLibraryService.

Public constructors

Public methods

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

Returns the children under a parent id.

ListenableFuture<LibraryResult<MediaItem>>
getItem(String mediaId)

Returns the media item with the given media id.

ListenableFuture<LibraryResult<MediaItem>>

Returns the library root item.

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

Returns the search result from the library service.

ListenableFuture<LibraryResult<Void>>

Requests a search from the library service.

ListenableFuture<LibraryResult<Void>>
subscribe(
    String parentId,
    @Nullable MediaLibraryService.LibraryParams params
)

Subscribes to a parent id for changes to its children.

ListenableFuture<LibraryResult<Void>>
unsubscribe(String parentId)

Unsubscribes from a parent id for changes to its children, which was previously subscribed by subscribe.

Inherited Constants

From androidx.media3.session.MediaController
static final long

The timeout for handling pending commands after calling release.

From androidx.media3.common.Player
static final int

Command to increase and decrease the device volume and mute it.

static final int

Command to change the MediaItems in the playlist.

static final int

Command to get the player current AudioAttributes.

static final int

Command to get the currently playing MediaItem.

static final int

Command to get the device volume and whether it is muted.

static final int

Command to get the MediaItems metadata.

static final int

Command to get the text that should currently be displayed by the player.

static final int

Command to get the information about the current timeline.

static final int

Command to get details of the current track selection.

static final int

Command to get the player volume.

static final int

Represents an invalid Command.

static final int

Command to start, pause or resume playback.

static final int

Command to prepare the player.

static final int

Command to seek back by a fixed increment into the current MediaItem.

static final int

Command to seek forward by a fixed increment into the current MediaItem.

static final int

Command to seek anywhere into the current MediaItem.

static final int

This field is deprecated.

Use COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM instead.

static final int

Command to seek to the default position of the current MediaItem.

static final int

Command to seek anywhere in any MediaItem.

static final int

Command to seek to a later position in the current or next MediaItem.

static final int

Command to seek to the default position of the next MediaItem.

static final int

This field is deprecated.

Use COMMAND_SEEK_TO_NEXT_MEDIA_ITEM instead.

static final int

Command to seek to an earlier position in the current or previous MediaItem.

static final int

Command to seek to the default position of the previous MediaItem.

static final int

This field is deprecated.

Use COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM instead.

static final int

This field is deprecated.

Use COMMAND_SEEK_TO_MEDIA_ITEM instead.

static final int

Command to set the device volume and mute it.

static final int

Command to set a MediaItem.

static final int

Command to set the MediaItems metadata.

static final int

Command to set the repeat mode.

static final int

Command to enable shuffling.

static final int

Command to set the playback speed and pitch.

static final int

Command to set the player's track selection parameters.

static final int

Command to set and clear the surface on which to render the video.

static final int

Command to set the player volume.

static final int

Command to stop playback or release the player.

static final int

Automatic playback transition from one period in the timeline to the next.

static final int

Discontinuity introduced internally (e.g. by the source).

static final int

Discontinuity caused by the removal of the current period from the Timeline.

static final int

Seek within the current period or to another period.

static final int

Seek adjustment due to being unable to seek to the requested position or because the seek was permitted to be inexact.

static final int

Discontinuity introduced by a skipped period (for instance a skipped ad).

static final int

getAudioAttributes changed.

static final int

The audio session id was set.

static final int

isCommandAvailable changed for at least one Command.

static final int

getCurrentCues changed.

static final int

getDeviceInfo changed.

static final int

getDeviceVolume changed.

static final int

isLoading ()} changed.

static final int

isPlaying changed.

static final int

getMaxSeekToPreviousPosition changed.

static final int

getCurrentMediaItem changed or the player started repeating the current item.

static final int

getMediaMetadata changed.

static final int

Metadata associated with the current playback time changed.

static final int

getPlaybackParameters changed.

static final int

getPlaybackState changed.

static final int

getPlaybackSuppressionReason changed.

static final int

getPlayerError changed.

static final int

getPlaylistMetadata changed.

static final int

getPlayWhenReady changed.

static final int

A position discontinuity occurred.

static final int

A frame is rendered for the first time since setting the surface, or since the renderer was reset, or since the stream being rendered was changed.

static final int

getRepeatMode changed.

static final int

getSeekBackIncrement changed.

static final int

getSeekForwardIncrement changed.

static final int

getShuffleModeEnabled changed.

static final int

Skipping silences in the audio stream is enabled or disabled.

static final int

The size of the surface onto which the video is being rendered changed.

static final int

getCurrentTimeline changed.

static final int

getCurrentTracks changed.

static final int

getTrackSelectionParameters changed.

static final int

getVideoSize changed.

static final int

getVolume changed.

static final int

Playback has automatically transitioned to the next media item.

static final int

The current media item has changed because of a change in the playlist.

static final int

The media item has been repeated.

static final int

A seek to another media item has occurred.

static final int

Playback is not suppressed.

static final int

Playback is suppressed due to transient audio focus loss.

static final int

Playback has been paused to avoid becoming noisy.

static final int

Playback has been paused because of a loss of audio focus.

static final int

Playback has been paused at the end of a media item.

static final int

Playback has been started or paused because of a remote change.

static final int

Playback has been started or paused by a call to setPlayWhenReady.

static final int

Repeats the entire timeline infinitely.

static final int

Normal playback without repetition.

static final int

Repeats the currently playing MediaItem infinitely during ongoing playback.

static final int

The player is not able to immediately play the media, but is doing work toward being able to do so.

static final int

The player has finished playing the media.

static final int

The player is idle, meaning it holds only limited resources.

static final int

The player is able to immediately play from its current position.

static final int

Timeline changed as a result of a change of the playlist items or the order of the items.

static final int

Timeline changed as a result of a source update (e.g. result of a dynamic update by the played media).

Inherited methods

From androidx.media3.session.MediaController
void

Registers a listener to receive all events from the player.

void

Adds a media item to the end of the playlist.

void
addMediaItem(int index, MediaItem mediaItem)

Adds a media item at the given index of the playlist.

void

Adds a list of media items to the end of the playlist.

void
addMediaItems(int index, List<MediaItem> mediaItems)

Adds a list of media items at the given index of the playlist.

boolean

Returns whether the player can be used to advertise a media session.

void

Clears the playlist.

void

Clears any Surface, SurfaceHolder, SurfaceView or TextureView currently set on the player.

void

Clears the Surface onto which video is being rendered if it matches the one passed.

void

Clears the SurfaceHolder that holds the Surface onto which video is being rendered if it matches the one passed.

void

Clears the SurfaceView onto which video is being rendered if it matches the one passed.

void

Clears the TextureView onto which video is being rendered if it matches the one passed.

void

Decreases the volume of the device.

Looper

Returns the Looper associated with the application thread that's used to access the player and on which player events are received.

AudioAttributes

Returns the attributes for audio playback.

Player.Commands

Returns the player's currently available Commands.

SessionCommands

Returns the current available session commands from onAvailableSessionCommandsChanged, or EMPTY if it is not connected.

@IntRange(from = 0, to = 100) int

Returns an estimate of the percentage in the current content or ad up to which data is buffered, or 0 if no estimate is available.

long

Returns an estimate of the position in the current content or ad up to which data is buffered, in milliseconds.

@Nullable SessionToken

Returns the SessionToken of the connected session, or null if it is not connected.

long

If #isPlayingAd() returns true}, returns an estimate of the content position in the current content up to which data is buffered, in milliseconds.

long

If #isPlayingAd() returns true}, returns the duration of the current content in milliseconds, or C#TIME_UNSET if the duration is not known.

long

If #isPlayingAd() returns true}, returns the content position that will be played once all ads in the ad group have finished playing, in milliseconds.

int

If isPlayingAd returns true, returns the index of the ad group in the period currently being played.

int

If isPlayingAd returns true, returns the index of the ad in its ad group.

CueGroup

Returns the current CueGroup.

long

Returns the offset of the current playback position from the live edge in milliseconds, or TIME_UNSET if the current MediaItemisCurrentMediaItemLive isn't live} or the offset is unknown.

@Nullable Object

Returns null.

@Nullable MediaItem

Returns the currently playing MediaItem.

int

Returns the index of the current MediaItem in the timeline, or the prospective index if the current timeline is empty.

int

Returns the index of the period currently being played.

long

Returns the playback position in the current content or ad, in milliseconds, or the prospective position in milliseconds if the current timeline is empty.

Timeline

Returns the current .

Tracks

Returns the current tracks.

int

This method is deprecated.

Use getCurrentMediaItemIndex instead.

DeviceInfo

Gets the device information.

@IntRange(from = 0) int

Gets the current volume of the device.

long

Returns the duration of the current content or ad in milliseconds, or TIME_UNSET if the duration is not known.

long

Returns the maximum position for which #seekToPrevious() seeks to the previous * , in milliseconds.

MediaItem
getMediaItemAt(int index)

Returns the MediaItem at the given index.

int

Returns the number of media items in the playlist.

MediaMetadata

Returns the current combined MediaMetadata, or EMPTY if not supported.

int

Returns the index of the that will be played if * #seekToNextMediaItem() is called, which may depend on the current repeat mode and whether shuffle mode is enabled.

int

This method is deprecated.

Use getNextMediaItemIndex instead.

boolean

Whether playback will proceed when getPlaybackState == STATE_READY.

PlaybackParameters

Returns the currently active playback parameters.

int

Returns the current playback state of the player.

int

Returns the reason why playback is suppressed even though getPlayWhenReady is true, or PLAYBACK_SUPPRESSION_REASON_NONE if playback is not suppressed.

@Nullable PlaybackException

Returns the error that caused playback to fail.

MediaMetadata

Returns the playlist MediaMetadata, as set by setPlaylistMetadata, or EMPTY if not supported.

int

Returns the index of the that will be played if * #seekToPreviousMediaItem() is called, which may depend on the current repeat mode and whether shuffle mode is enabled.

int

This method is deprecated.

Use getPreviousMediaItemIndex instead.

int

Returns the current RepeatMode used for playback.

long

Returns the #seekBack() increment.

long

Returns the #seekForward() increment.

@Nullable PendingIntent

Returns an intent for launching UI associated with the session if exists, or null.

boolean

Returns whether shuffling of media items is enabled.

Size

Gets the size of the surface on which the video is rendered.

long

Returns an estimate of the total buffered duration from the current position, in milliseconds.

TrackSelectionParameters

Returns the parameters constraining the track selection.

VideoSize

Gets the size of the video.

@FloatRange(from = 0, to = 1) float

Returns the audio volume, with 0 being silence and 1 being unity gain (signal unchanged).

boolean

This method is deprecated.

Use hasNextMediaItem instead.

boolean

Returns whether a next MediaItem exists, which may depend on the current repeat mode and whether shuffle mode is enabled.

boolean

This method is deprecated.

Use hasNextMediaItem instead.

boolean

This method is deprecated.

Use hasPreviousMediaItem instead.

boolean

Returns whether a previous media item exists, which may depend on the current repeat mode and whether shuffle mode is enabled.

boolean

This method is deprecated.

Use hasPreviousMediaItem instead.

void

Increases the volume of the device.

boolean

Returns whether the provided Command is available.

boolean

Returns whether this controller is connected to a MediaSession or not.

boolean

Returns whether the current MediaItem is dynamic (may change when the Timeline is updated), or false if the Timeline is empty.

boolean

Returns whether the current MediaItem is live, or false if the Timeline is empty.

boolean

Returns whether the current MediaItem is seekable, or false if the is empty.

boolean

This method is deprecated.

Use isCurrentMediaItemDynamic instead.

boolean

This method is deprecated.

Use isCurrentMediaItemLive instead.

boolean

This method is deprecated.

Use isCurrentMediaItemSeekable instead.

boolean

Gets whether the device is muted or not.

boolean

Whether the player is currently loading the source.

boolean

Returns whether the player is playing, i.e. getCurrentPosition is advancing.

boolean

Returns whether the player is currently playing an ad.

boolean

Returns whether the SessionCommand is available.

boolean
isSessionCommandAvailable(
    @SessionCommand.CommandCode int sessionCommandCode
)

Returns whether the SessionCommand.CommandCode is available.

void
moveMediaItem(int currentIndex, int newIndex)

Moves the media item at the current index to the new index.

void
moveMediaItems(int fromIndex, int toIndex, int newIndex)

Moves the media item range to the new index.

void

This method is deprecated.

Use seekToNextMediaItem instead.

void

Pauses playback.

void

Resumes playback as soon as getPlaybackState == STATE_READY.

void

Prepares the player.

void

This method is deprecated.

Use seekToPreviousMediaItem instead.

void

Releases the connection between MediaController and MediaSession.

static void

Releases the future controller returned by buildAsync.

void

Unregister a listener registered through addListener.

void
removeMediaItem(int index)

Removes the media item at the given index of the playlist.

void
removeMediaItems(int fromIndex, int toIndex)

Removes a range of media items from the playlist.

void

Seeks back in the current by #getSeekBackIncrement() milliseconds.

void

Seeks forward in the current by #getSeekForwardIncrement() milliseconds.

void
seekTo(long positionMs)

Seeks to a position specified in milliseconds in the current MediaItem.

void
seekTo(int mediaItemIndex, long positionMs)

Seeks to a position specified in milliseconds in the specified MediaItem.

void

Seeks to the default position associated with the current MediaItem.

void
seekToDefaultPosition(int mediaItemIndex)

Seeks to the default position associated with the specified MediaItem.

void

Seeks to a later position in the current or next (if available).

void

Seeks to the default position of the next , which may depend on the current repeat mode and whether shuffle mode is enabled.

void

This method is deprecated.

Use seekToNextMediaItem instead.

void

Seeks to an earlier position in the current or previous (if available).

void

Seeks to the default position of the previous , which may depend on the current repeat mode and whether shuffle mode is enabled.

void

This method is deprecated.

Use seekToPreviousMediaItem instead.

ListenableFuture<SessionResult>

Sends a custom command to the session.

void
setDeviceMuted(boolean muted)

Sets the mute state of the device.

void
setDeviceVolume(@IntRange(from = 0) int volume)

Sets the volume of the device.

void

Clears the playlist, adds the specified MediaItem and resets the position to the default position.

void
setMediaItem(MediaItem mediaItem, boolean resetPosition)

Clears the playlist and adds the specified MediaItem.

void
setMediaItem(MediaItem mediaItem, long startPositionMs)

Clears the playlist and adds the specified MediaItem.

void

Clears the playlist, adds the specified MediaItems and resets the position to the default position.

void
setMediaItems(List<MediaItem> mediaItems, boolean resetPosition)

Clears the playlist and adds the specified MediaItems.

void
setMediaItems(
    List<MediaItem> mediaItems,
    int startIndex,
    long startPositionMs
)

Clears the playlist and adds the specified MediaItems.

void
setPlayWhenReady(boolean playWhenReady)

Sets whether playback should proceed when getPlaybackState == STATE_READY.

void

Attempts to set the playback parameters.

void
setPlaybackSpeed(float speed)

Changes the rate at which playback occurs.

void

Sets the playlist MediaMetadata.

ListenableFuture<SessionResult>
setRating(Rating rating)

Requests that the connected MediaSession rates the current media item.

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

Requests that the connected MediaSession rates the media.

void

Sets the RepeatMode to be used for playback.

void
setShuffleModeEnabled(boolean shuffleModeEnabled)

Sets whether shuffling of media items is enabled.

void

Sets the parameters constraining the track selection.

void

Sets the Surface onto which video will be rendered.

void

Sets the SurfaceHolder that holds the Surface onto which video will be rendered.

void

Sets the SurfaceView onto which video will be rendered.

void

Sets the TextureView onto which video will be rendered.

void
setVolume(@FloatRange(from = 0, to = 1) float volume)

Sets the audio volume, valid values are between 0 (silence) and 1 (unity gain, signal unchanged), inclusive.

void

Stops playback without resetting the playlist.

void
@UnstableApi
stop(boolean reset)

This method is deprecated.

Use stop and clearMediaItems (if reset is true) or just stop (if reset is false).

From androidx.media3.common.Player
abstract void

Registers a listener to receive all events from the player.

abstract void

Unregister a listener registered through addListener.

abstract void
setPlaybackSpeed(@FloatRange(from = 0, fromInclusive = false) float speed)

Changes the rate at which playback occurs.

abstract void

Sets the playlist MediaMetadata.

abstract void
setVolume(@FloatRange(from = 0, to = 1.0) float volume)

Sets the audio volume, valid values are between 0 (silence) and 1 (unity gain, signal unchanged), inclusive.