MediaPlayer
class MediaPlayer : SessionPlayer
kotlin.Any | ||
↳ | androidx.media2.common.SessionPlayer | |
↳ | androidx.media2.player.MediaPlayer |
A media player which plays MediaItem
s. The details on playback control and player states can be found in the documentation of the base class, SessionPlayer
.
Topic covered here:
Audio focus and noisy intent
By default, MediaPlayer
handles audio focus and noisy intent with AudioAttributesCompat
set to this player. You need to call setAudioAttributes(AudioAttributesCompat)
set the audio attribute while in the PLAYER_STATE_IDLE
.
Here's the table of automatic audio focus behavior with audio attributes.
If an AudioAttributesCompat
is not specified by setAudioAttributes
, getAudioAttributes
will return null
and the default audio focus behavior will follow the null
case on the table above.
For more information about the audio focus, take a look at Managing audio focus
Summary
Nested classes | |
---|---|
abstract |
Interface definition for callbacks to be invoked when the player has the corresponding events. |
Class for the player to return each audio/video/subtitle track's metadata. |
Constants | |
---|---|
static Int |
Informs that audio is not playing. |
static Int |
Bad interleaving means that a media has been improperly interleaved or not interleaved at all, e. |
static Int |
Update status in buffering a media source received through progressive downloading. |
static Int |
A new set of metadata is available. |
static Int |
The media cannot be seeked (e.g live stream) |
static Int |
Informs that video is not playing. |
static Int |
The player just pushed the very first video frame for rendering. |
static Int |
The video is too complex for the decoder: it can't decode frames fast enough. |
static Int |
The return value of |
static Int |
File or network related operation errors. |
static Int |
Bitstream is not conforming to the related coding standard or file spec. |
static Int |
Some operation takes too long to complete, usually more than 3-5 seconds. |
static Int |
Unspecified player error. |
static Int |
Bitstream is conforming to the related coding standard or file spec, but the media framework does not support the feature. |
static Int |
This mode is used with |
static Int |
This mode is used with |
static Int |
This mode is used with |
static Int |
This mode is used with |
Inherited constants | |
---|---|
Public constructors | |
---|---|
Constructor to create a MediaPlayer instance. |
Public methods | |
---|---|
ListenableFuture<SessionPlayer.PlayerResult!> |
addPlaylistItem(index: Int, @NonNull item: MediaItem) Adds the media item to the playlist at the index. |
ListenableFuture<SessionPlayer.PlayerResult!> |
attachAuxEffect(effectId: Int) Attaches an auxiliary effect to the player. |
Unit |
close() Closes the player and relinquish underlying resources. |
ListenableFuture<SessionPlayer.PlayerResult!> |
deselectTrack(@NonNull trackInfo: SessionPlayer.TrackInfo) Deselects the |
AudioAttributesCompat? | |
Int |
Returns the audio session ID. |
Long | |
Int | |
MediaItem? | |
Int |
Gets the index of current media item in playlist. |
Long | |
Long | |
Float | |
Int |
Gets the next item index in the playlist. |
PlaybackParams |
Gets the playback params, containing the current playback rate. |
Float | |
Int | |
Float | |
MutableList<MediaItem |