belongs to Maven artifact androidx.media:media:1.0.0-alpha1

MediaPlayerInterface

public abstract class MediaPlayerInterface
extends Object implements AutoCloseable

java.lang.Object
   ↳ androidx.media.MediaPlayerInterface


Base interface for all media players that want media session.

Summary

Nested classes

class MediaPlayerInterface.PlayerEventCallback

A callback class to receive notifications for events on the media player. 

Constants

int BUFFERING_STATE_BUFFERING_AND_PLAYABLE

Buffering state indicating the player is buffering but enough has been buffered for this player to be able to play the content.

int BUFFERING_STATE_BUFFERING_AND_STARVED

Buffering state indicating the player is buffering, but the player is currently starved for data, and cannot play.

int BUFFERING_STATE_BUFFERING_COMPLETE

Buffering state indicating the player is done buffering, and the remainder of the content is available for playback.

int BUFFERING_STATE_UNKNOWN

Buffering state is unknown.

int PLAYER_STATE_ERROR

State when the player is in error state and cannot be recovered self.

int PLAYER_STATE_IDLE

State when the player is idle, and needs configuration to start playback.

int PLAYER_STATE_PAUSED

State when the player's playback is paused

int PLAYER_STATE_PLAYING

State when the player's playback is ongoing

long UNKNOWN_TIME

Public constructors

MediaPlayerInterface()

Public methods

abstract AudioAttributesCompat getAudioAttributes()

Returns AudioAttributes that media player has.

long getBufferedPosition()

Gets the buffered position of current playback, or UNKNOWN_TIME if unknown.

abstract int getBufferingState()

Returns the current buffering state of the player.

abstract DataSourceDesc getCurrentDataSource()

Returns the current data source.

long getCurrentPosition()

Gets the current playback head position.

long getDuration()

Returns the duration of the current data source, or UNKNOWN_TIME if unknown.

float getMaxPlayerVolume()
float getPlaybackSpeed()

Returns the actual playback speed to be used by the player when playing.

abstract int getPlayerState()

Returns the current player state.

abstract float getPlayerVolume()

Returns the current volume of this player to this player.

boolean isReversePlaybackSupported()

Indicates whether reverse playback is supported.

abstract void loopCurrent(boolean loop)

Configures the player to loop on the current data source.

abstract void pause()

Pauses playback.

abstract void play()

Starts or resumes playback.

abstract void prepare()

Prepares the player for playback.

abstract void registerPlayerEventCallback(Executor e, MediaPlayerInterface.PlayerEventCallback cb)

Adds a callback to be notified of events for this player.

abstract void reset()

Resets the MediaPlayerInterface to its uninitialized state.

abstract void seekTo(long pos)

Moves the playback head to the specified position

abstract void setAudioAttributes(AudioAttributesCompat attributes)

Sets the AudioAttributesCompat to be used during the playback of the media.

abstract void setDataSource(DataSourceDesc dsd)

Sets the data source to be played.

abstract void setNextDataSource(DataSourceDesc dsd)

Sets the data source that will be played immediately after the current one is done playing.

abstract void setNextDataSources(List<DataSourceDesc> dsds)

Sets the list of data sources that will be sequentially played after the current one.

abstract void setPlaybackSpeed(float speed)

Sets the playback speed.

abstract void setPlayerVolume(float volume)

Sets the volume of the audio of the media to play, expressed as a linear multiplier on the audio samples.

abstract void skipToNext()

abstract void unregisterPlayerEventCallback(MediaPlayerInterface.PlayerEventCallback cb)

Removes a previously registered callback for player events

Inherited methods

Constants

BUFFERING_STATE_BUFFERING_AND_PLAYABLE

int BUFFERING_STATE_BUFFERING_AND_PLAYABLE

Buffering state indicating the player is buffering but enough has been buffered for this player to be able to play the content. See getBufferedPosition() for how far is buffered already.

Constant Value: 1 (0x00000001)

BUFFERING_STATE_BUFFERING_AND_STARVED

int BUFFERING_STATE_BUFFERING_AND_STARVED

Buffering state indicating the player is buffering, but the player is currently starved for data, and cannot play.

Constant Value: 2 (0x00000002)

BUFFERING_STATE_BUFFERING_COMPLETE

int BUFFERING_STATE_BUFFERING_COMPLETE

Buffering state indicating the player is done buffering, and the remainder of the content is available for playback.

Constant Value: 3 (0x00000003)

BUFFERING_STATE_UNKNOWN

int BUFFERING_STATE_UNKNOWN

Buffering state is unknown.

Constant Value: 0 (0x00000000)

PLAYER_STATE_ERROR

int PLAYER_STATE_ERROR

State when the player is in error state and cannot be recovered self.

Constant Value: 3 (0x00000003)

PLAYER_STATE_IDLE

int PLAYER_STATE_IDLE

State when the player is idle, and needs configuration to start playback.

Constant Value: 0 (0x00000000)

PLAYER_STATE_PAUSED

int PLAYER_STATE_PAUSED

State when the player's playback is paused

Constant Value: 1 (0x00000001)

PLAYER_STATE_PLAYING

int PLAYER_STATE_PLAYING

State when the player's playback is ongoing

Constant Value: 2 (0x00000002)

UNKNOWN_TIME

long UNKNOWN_TIME

Constant Value: -1 (0xffffffffffffffff)

Public constructors

MediaPlayerInterface

MediaPlayerInterface ()

Public methods

getAudioAttributes

AudioAttributesCompat getAudioAttributes ()

Returns AudioAttributes that media player has.

Returns
AudioAttributesCompat

getBufferedPosition

long getBufferedPosition ()

Gets the buffered position of current playback, or UNKNOWN_TIME if unknown.

Returns
long the buffered position in ms, or UNKNOWN_TIME.

getBufferingState

int getBufferingState ()

Returns the current buffering state of the player. During buffering, see getBufferedPosition() for the quantifying the amount already buffered.

Returns
int the buffering state.

getCurrentDataSource

DataSourceDesc getCurrentDataSource ()

Returns the current data source.

Returns
DataSourceDesc the current data source, or null if none is set, or none available to play.

getCurrentPosition

long getCurrentPosition ()

Gets the current playback head position.

Returns
long the current playback position in ms, or UNKNOWN_TIME if unknown.

getDuration

long getDuration ()

Returns the duration of the current data source, or UNKNOWN_TIME if unknown.

Returns
long the duration in ms, or UNKNOWN_TIME.

getMaxPlayerVolume

float getMaxPlayerVolume ()

Returns
float the maximum volume that can be used in setPlayerVolume(float).

getPlaybackSpeed

float getPlaybackSpeed ()

Returns the actual playback speed to be used by the player when playing. Note that it may differ from the speed set in setPlaybackSpeed(float).

Returns
float the actual playback speed

getPlayerState

int getPlayerState ()

Returns the current player state. See also MediaPlayerInterface.PlayerEventCallback.onPlayerStateChanged(MediaPlayerInterface, int) for notification of changes.

Returns
int the current player state

getPlayerVolume

float getPlayerVolume ()

Returns the current volume of this player to this player. Note that it does not take into account the associated stream volume.

Returns
float the player volume.

isReversePlaybackSupported

boolean isReversePlaybackSupported ()

Indicates whether reverse playback is supported. Reverse playback is indicated by negative playback speeds, see setPlaybackSpeed(float).

Returns
boolean true if reverse playback is supported.

loopCurrent

void loopCurrent (boolean loop)

Configures the player to loop on the current data source.

Parameters
loop boolean: true if the current data source is meant to loop.

pause

void pause ()

Pauses playback.

play

void play ()

Starts or resumes playback.

prepare

void prepare ()

Prepares the player for playback. See MediaPlayerInterface.PlayerEventCallback.onMediaPrepared(MediaPlayerInterface, DataSourceDesc) for being notified when the preparation phase completed. During this time, the player may allocate resources required to play, such as audio and video decoders.

registerPlayerEventCallback

void registerPlayerEventCallback (Executor e, 
                MediaPlayerInterface.PlayerEventCallback cb)

Adds a callback to be notified of events for this player.

Parameters
e Executor: the Executor to be used for the events.

cb MediaPlayerInterface.PlayerEventCallback: the callback to receive the events.

reset

void reset ()

Resets the MediaPlayerInterface to its uninitialized state.

seekTo

void seekTo (long pos)

Moves the playback head to the specified position

Parameters
pos long: the new playback position expressed in ms.

setAudioAttributes

void setAudioAttributes (AudioAttributesCompat attributes)

Sets the AudioAttributesCompat to be used during the playback of the media.

Parameters
attributes AudioAttributesCompat: non-null AudioAttributes.

setDataSource

void setDataSource (DataSourceDesc dsd)

Sets the data source to be played.

setNextDataSource

void setNextDataSource (DataSourceDesc dsd)

Sets the data source that will be played immediately after the current one is done playing.

setNextDataSources

void setNextDataSources (List<DataSourceDesc> dsds)

Sets the list of data sources that will be sequentially played after the current one. Each data source is played immediately after the previous one is done playing.

setPlaybackSpeed

void setPlaybackSpeed (float speed)

Sets the playback speed. A value of 1.0f is the default playback value. A negative value indicates reverse playback, check isReversePlaybackSupported() before using negative values.
After changing the playback speed, it is recommended to query the actual speed supported by the player, see getPlaybackSpeed().

setPlayerVolume

void setPlayerVolume (float volume)

Sets the volume of the audio of the media to play, expressed as a linear multiplier on the audio samples. Note that this volume is specific to the player, and is separate from stream volume used across the platform.
A value of 0.0f indicates muting, a value of 1.0f is the nominal unattenuated and unamplified gain. See getMaxPlayerVolume() for the volume range supported by this player.

Parameters
volume float: a value between 0.0f and getMaxPlayerVolume().

skipToNext

void skipToNext ()

unregisterPlayerEventCallback

void unregisterPlayerEventCallback (MediaPlayerInterface.PlayerEventCallback cb)

Removes a previously registered callback for player events

Parameters
cb MediaPlayerInterface.PlayerEventCallback: the callback to remove