class MediaBrowser : MediaController


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

Summary

Nested types

A builder for MediaBrowser.

A listener for events from MediaLibraryService.

Public functions

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

Returns the children under a parent id.

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

Returns the media item with the given media id.

ListenableFuture<LibraryResult<MediaItem!>!>!

Returns the library root item.

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

Returns the search result from the library service.

ListenableFuture<LibraryResult<Void!>!>!

Requests a search from the library service.

ListenableFuture<LibraryResult<Void!>!>!

Subscribes to a parent id for changes to its children.

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

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

Inherited Constants

From androidx.media3.session.MediaController
const String!
@UnstableApi
KEY_MEDIA_NOTIFICATION_CONTROLLER_FLAG = "androidx.media3.session.MediaNotificationManager"

Key to mark the connection hints of the media notification controller.

const Long

The timeout for handling pending commands after calling release.

From androidx.media3.common.Player
const Int

This property is deprecated.

Use COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS instead.

const Int

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

const Int

Command to change the media items in the playlist.

const Int

Command to get the player current AudioAttributes.

const Int

Command to get information about the currently playing MediaItem.

const Int

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

const Int

This property is deprecated.

Use COMMAND_GET_METADATA instead.

const Int

Command to get metadata related to the playlist and current MediaItem.

const Int

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

const Int

Command to get the information about the current timeline.

const Int

Command to get details of the current track selection.

const Int

Command to get the player volume.

const Int

Represents an invalid Command.

const Int

Command to start, pause or resume playback.

const Int

Command to prepare the player.

const Int

Command to release the player.

const Int

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

const Int

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

const Int

Command to seek anywhere inside the current MediaItem.

const Int

This property is deprecated.

Use COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM instead.

const Int

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

const Int

Command to seek anywhere in any MediaItem.

const Int

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

const Int

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

const Int

This property is deprecated.

Use COMMAND_SEEK_TO_NEXT_MEDIA_ITEM instead.

const Int

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

const Int

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

const Int

This property is deprecated.

Use COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM instead.

const Int

This property is deprecated.

Use COMMAND_SEEK_TO_MEDIA_ITEM instead.

const Int

Command to set the player's audio attributes.

const Int

This property is deprecated.

Use COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS instead.

const Int

Command to set the device volume with volume flags.

const Int

Command to set a MediaItem.

const Int

This property is deprecated.

Use COMMAND_SET_PLAYLIST_METADATA instead.

const Int

Command to set the playlist metadata.

const Int

Command to set the repeat mode.

const Int

Command to enable shuffling.

const Int

Command to set the playback speed and pitch.

const Int

Command to set the player's track selection parameters.

const Int

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

const Int

Command to set the player volume.

const Int

Command to stop playback.

const Int

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

const Int

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

const Int

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

const Int

Seek within the current period or to another period.

const Int

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

const Int

Discontinuity introduced by a skipped silence.

const Int

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

const Int

getAudioAttributes changed.

const Int

The audio session id was set.

const Int

isCommandAvailable changed for at least one Command.

const Int

getCurrentCues changed.

const Int

getDeviceInfo changed.

const Int

getDeviceVolume changed.

const Int

isLoading ()} changed.

const Int

isPlaying changed.

const Int

getMaxSeekToPreviousPosition changed.

const Int

getCurrentMediaItem changed or the player started repeating the current item.

const Int

getMediaMetadata changed.

const Int

Metadata associated with the current playback time changed.

const Int

getPlaybackParameters changed.

const Int

getPlaybackState changed.

const Int

getPlaybackSuppressionReason changed.

const Int

getPlayerError changed.

const Int

getPlaylistMetadata changed.

const Int

getPlayWhenReady changed.

const Int

A position discontinuity occurred.

const 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.

const Int

getRepeatMode changed.

const Int

getSeekBackIncrement changed.

const Int

getSeekForwardIncrement changed.

const Int

getShuffleModeEnabled changed.

const Int

Skipping silences in the audio stream is enabled or disabled.

const Int

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

const Int

getCurrentTimeline changed.

const Int

getCurrentTracks changed.

const Int

getTrackSelectionParameters changed.

const Int

getVideoSize changed.

const Int

getVolume changed.

const Int

Playback has automatically transitioned to the next media item.

const Int

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

const Int

The media item has been repeated.

const Int

A seek to another media item has occurred.

const Int

Playback is not suppressed.

const Int

Playback is suppressed due to transient audio focus loss.

const Int

Playback is suppressed due to attempt to play on an unsuitable audio output (e.g. attempt to play on built-in speaker on a Wear OS device).

const Int

This property is deprecated.

Use PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT instead.

const Int

Playback has been paused to avoid becoming noisy.

const Int

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

const Int

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

const Int

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

const Int

Playback has been paused because playback has been suppressed too long.

const Int

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

const Int

Repeats the entire timeline infinitely.

const Int

Normal playback without repetition.

const Int

Repeats the currently playing MediaItem infinitely during ongoing playback.

const Int

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

const Int

The player has finished playing the media.

const Int

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

const Int

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

const Int

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

const Int

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

Inherited functions

From androidx.media3.session.MediaController
Unit

Registers a listener to receive all events from the player.

Unit
addMediaItem(mediaItem: MediaItem!)

Adds a media item to the end of the playlist.

Unit
addMediaItem(index: Int, mediaItem: MediaItem!)

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

Unit

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

Unit
addMediaItems(index: Int, mediaItems: (Mutable)List<MediaItem!>!)

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.

Unit

Clears the playlist.

Unit

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

Unit

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

Unit

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

Unit

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

Unit

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

Unit

This function is deprecated.

Use decreaseDeviceVolume instead.

Unit

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.

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 MediaItemisn't live or the offset is unknown.

Any?

Returns null.

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 function is deprecated.

Use getCurrentMediaItemIndex instead.

ImmutableList<CommandButton!>!

Returns the custom layout.

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!

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 function 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.

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 function is deprecated.

Use getPreviousMediaItemIndex instead.

Int

Returns the current RepeatMode used for playback.

Long

Returns the #seekBack() increment.

Long

Returns the #seekForward() increment.

PendingIntent?

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

Bundle!

Returns the session extras.

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 function 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 function is deprecated.

Use hasNextMediaItem instead.

Boolean

This function 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 function is deprecated.

Use hasPreviousMediaItem instead.

Unit

This function is deprecated.

Use increaseDeviceVolume instead.

Unit

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 function is deprecated.

Use isCurrentMediaItemDynamic instead.

Boolean

This function is deprecated.

Use isCurrentMediaItemLive instead.

Boolean

This function 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.CommandCode is available.

Boolean

Returns whether the SessionCommand is available.

Unit
moveMediaItem(currentIndex: Int, newIndex: Int)

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

Unit
moveMediaItems(fromIndex: Int, toIndex: Int, newIndex: Int)

Moves the media item range to the new index.

Unit

This function is deprecated.

Use seekToNextMediaItem instead.

Unit

Pauses playback.

Unit

Resumes playback as soon as getPlaybackState == STATE_READY.

Unit

Prepares the player.

Unit

This function is deprecated.

Use seekToPreviousMediaItem instead.

Unit

Releases the connection between MediaController and MediaSession.

java-static Unit
releaseFuture(controllerFuture: Future<MediaController!>!)

Releases the future controller returned by buildAsync.

Unit

Unregister a listener registered through addListener.

Unit

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

Unit
removeMediaItems(fromIndex: Int, toIndex: Int)

Removes a range of media items from the playlist.

Unit
replaceMediaItem(index: Int, mediaItem: MediaItem!)

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

Unit
replaceMediaItems(
    fromIndex: Int,
    toIndex: Int,
    mediaItems: (Mutable)List<MediaItem!>!
)

Replaces the media items at the given range of the playlist.

Unit

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

Unit

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

Unit
seekTo(positionMs: Long)

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

Unit
seekTo(mediaItemIndex: Int, positionMs: Long)

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

Unit

Seeks to the default position associated with the current MediaItem.

Unit
seekToDefaultPosition(mediaItemIndex: Int)

Seeks to the default position associated with the specified MediaItem.

Unit

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

Unit

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

Unit

This function is deprecated.

Use seekToNextMediaItem instead.

Unit

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

Unit

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

Unit

This function is deprecated.

Use seekToPreviousMediaItem instead.

ListenableFuture<SessionResult!>!

Sends a custom command to the session.

Unit
setAudioAttributes(
    audioAttributes: AudioAttributes!,
    handleAudioFocus: Boolean
)

Sets the attributes for audio playback, used by the underlying audio track.

Unit

This function is deprecated.

Use setDeviceMuted instead.

Unit

Sets the mute state of the device.

Unit
setDeviceVolume(volume: @IntRange(from = 0) Int)

This function is deprecated.

Use setDeviceVolume instead.

Unit
setDeviceVolume(volume: @IntRange(from = 0) Int, @C.VolumeFlags flags: Int)

Sets the volume of the device with volume flags.

Unit
setMediaItem(mediaItem: MediaItem!)

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

Unit
setMediaItem(mediaItem: MediaItem!, resetPosition: Boolean)

Clears the playlist and adds the specified MediaItem.

Unit
setMediaItem(mediaItem: MediaItem!, startPositionMs: Long)

Clears the playlist and adds the specified MediaItem.

Unit

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

Unit
setMediaItems(
    mediaItems: (Mutable)List<MediaItem!>!,
    resetPosition: Boolean
)

Clears the playlist and adds the specified media items.

Unit
setMediaItems(
    mediaItems: (Mutable)List<MediaItem!>!,
    startIndex: Int,
    startPositionMs: Long
)

Clears the playlist and adds the specified media items.

Unit
setPlayWhenReady(playWhenReady: Boolean)

Sets whether playback should proceed when getPlaybackState == STATE_READY.

Unit

Attempts to set the playback parameters.

Unit

Changes the rate at which playback occurs.

Unit
setPlaylistMetadata(playlistMetadata: MediaMetadata!)

Sets the playlist MediaMetadata.

ListenableFuture<SessionResult!>!
setRating(rating: Rating!)

Requests that the connected MediaSession rates the current media item.

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

Requests that the connected MediaSession rates the media.

Unit

Sets the RepeatMode to be used for playback.

Unit
setShuffleModeEnabled(shuffleModeEnabled: Boolean)

Sets whether shuffling of media items is enabled.

Unit

Sets the parameters constraining the track selection.

Unit

Sets the Surface onto which video will be rendered.

Unit

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

Unit

Sets the SurfaceView onto which video will be rendered.

Unit

Sets the TextureView onto which video will be rendered.

Unit
setVolume(volume: @FloatRange(from = 0, to = 1) Float)

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

Unit

Stops playback without resetting the playlist.

From androidx.media3.common.Player
abstract Unit

Registers a listener to receive all events from the player.

abstract Unit

Unregister a listener registered through addListener.

abstract Unit
setMediaItems(
    mediaItems: (Mutable)List<MediaItem!>!,
    startIndex: Int,
    startPositionMs: Long
)

Clears the playlist and adds the specified media items.

abstract Unit
setPlaybackSpeed(speed: @FloatRange(from = 0, fromInclusive = false) Float)

Changes the rate at which playback occurs.

abstract Unit

Sets the playlist MediaMetadata.

abstract Unit
setVolume(volume: @FloatRange(from = 0, to = 1.0) Float)

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

Public functions

getChildren

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

Returns the children under a parent id.

If it's successfully completed, value will have the children.

Parameters
parentId: String!

A non-empty parent id for getting the children.

page: @IntRange(from = 0) Int

A page number to get the paginated result starting from 0.

pageSize: @IntRange(from = 1) Int

A page size to get the paginated result. Should be greater than 0.

params: MediaLibraryService.LibraryParams?

Optional parameters.

Returns
ListenableFuture<LibraryResult<ImmutableList<MediaItem!>!>!>!

A ListenableFuture of LibraryResult that represents the pending result.

getItem

fun getItem(mediaId: String!): ListenableFuture<LibraryResult<MediaItem!>!>!

Returns the media item with the given media id.

If it's successfully completed, value will have the media item.

Parameters
mediaId: String!

A non-empty media id.

Returns
ListenableFuture<LibraryResult<MediaItem!>!>!

A ListenableFuture of LibraryResult that represents the pending result.

getLibraryRoot

fun getLibraryRoot(params: MediaLibraryService.LibraryParams?): ListenableFuture<LibraryResult<MediaItem!>!>!

Returns the library root item.

If it's successfully completed, value will have the library root item.

Parameters
params: MediaLibraryService.LibraryParams?

The optional parameters for getting library root item.

Returns
ListenableFuture<LibraryResult<MediaItem!>!>!

A ListenableFuture of LibraryResult that represents the pending result.

getSearchResult

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

Returns the search result from the library service.

If it's successfully completed, value will have the search result.

Parameters
query: String!

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

page: @IntRange(from = 0) Int

A page number to get the paginated result starting from 0.

pageSize: @IntRange(from = 1) Int

A page size to get the paginated result. Should be greater than 0.

params: MediaLibraryService.LibraryParams?

Optional parameters.

Returns
ListenableFuture<LibraryResult<ImmutableList<MediaItem!>!>!>!

A ListenableFuture of LibraryResult that represents the pending result.

search

fun search(query: String!, params: MediaLibraryService.LibraryParams?): ListenableFuture<LibraryResult<Void!>!>!

Requests a search from the library service.

Returned LibraryResult will only tell whether the attempt to search was successful. For getting the search result, listen to onSearchResultChanged and call getSearchResult}.

Parameters
query: String!

A non-empty search query.

params: MediaLibraryService.LibraryParams?

Optional parameters.

Returns
ListenableFuture<LibraryResult<Void!>!>!

A ListenableFuture of LibraryResult that represents the pending result.

subscribe

fun subscribe(parentId: String!, params: MediaLibraryService.LibraryParams?): ListenableFuture<LibraryResult<Void!>!>!

Subscribes to a parent id for changes to its children. When there's a change, onChildrenChanged will be called with the LibraryParams. You may call getChildren to get the children.

Parameters
parentId: String!

A non-empty parent id to subscribe to.

params: MediaLibraryService.LibraryParams?

Optional parameters.

Returns
ListenableFuture<LibraryResult<Void!>!>!

A ListenableFuture of LibraryResult that represents the pending result.

unsubscribe

fun unsubscribe(parentId: String!): ListenableFuture<LibraryResult<Void!>!>!

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

This unsubscribes from all previous subscriptions with the parent id, regardless of the LibraryParams that was previously given.

Parameters
parentId: String!

A non-empty parent id to unsubscribe from.

Returns
ListenableFuture<LibraryResult<Void!>!>!

A ListenableFuture of LibraryResult that represents the pending result.