PlayerAdapter


public abstract class PlayerAdapter

Known direct subclasses
LeanbackPlayerAdapter

Leanback PlayerAdapter implementation for Player.

MediaControllerAdapter

A helper class for implementing a adapter layer for MediaControllerCompat.

MediaPlayerAdapter

This implementation extends the PlayerAdapter with a MediaPlayer.


Base class that wraps underlying media player. The class is used by PlaybackGlue, for example PlaybackTransportControlGlue is bound to a PlayerAdapter. This class is intended to be subclassed, MediaPlayerAdapter is a concrete subclass using android.media.MediaPlayer. ExoPlayer also provides a leanback extension that implements PlayerAdapter. Please see ExoPlayer https://developer.android.com/guide/topics/media/exoplayer

Summary

Nested types

Client for client of PlayerAdapter.

Public constructors

Public methods

void

Optional method.

long

Returns the current buffered position of the media item in milliseconds.

final @Nullable PlayerAdapter.Callback

Gets callback for event of PlayerAdapter.

long

Returns the current position of the media item in milliseconds.

long

Returns the duration of the media item in milliseconds.

long

Return xor combination of values defined in PlaybackBaseControlGlue.

boolean

Returns true if media is currently playing.

boolean
void

Optional method.

void

This method is called attached to associated PlaybackGlueHost.

void

This method is called when current associated PlaybackGlueHost is attached to a different PlaybackGlue or PlaybackGlueHost is destroyed.

abstract void

Pauses the media player.

abstract void

Starts the media player.

void

Optional method.

void

Optional method.

void
seekTo(long positionInMs)

Seek to new position.

final void

Sets callback for event of PlayerAdapter.

void

Implement this method to enable or disable progress updating.

void
setRepeatAction(int repeatActionIndex)

Optional method.

void
setShuffleAction(int shuffleActionIndex)

Optional method.

Public constructors

PlayerAdapter

Added in 1.1.0
public PlayerAdapter()

Public methods

fastForward

Added in 1.1.0
public void fastForward()

Optional method. Override this method if getSupportedActions include ACTION_FAST_FORWARD to fast forward current media item.

getBufferedPosition

Added in 1.1.0
public long getBufferedPosition()

Returns the current buffered position of the media item in milliseconds.

getCallback

Added in 1.1.0
public final @Nullable PlayerAdapter.Callback getCallback()

Gets callback for event of PlayerAdapter.

Returns
@Nullable PlayerAdapter.Callback

Client for event of PlayerAdapter.

getCurrentPosition

Added in 1.1.0
public long getCurrentPosition()

Returns the current position of the media item in milliseconds.

getDuration

Added in 1.1.0
public long getDuration()

Returns the duration of the media item in milliseconds.

getSupportedActions

Added in 1.1.0
public long getSupportedActions()

Return xor combination of values defined in PlaybackBaseControlGlue. Default is PLAY_PAUSE (unless subclass enforce to be 0)

isPlaying

Added in 1.1.0
public boolean isPlaying()

Returns true if media is currently playing.

isPrepared

Added in 1.1.0
public boolean isPrepared()
Returns
boolean

True if media is ready for playback, false otherwise.

next

Added in 1.1.0
public void next()

Optional method. Override this method if getSupportedActions include ACTION_SKIP_TO_NEXT to skip to next item.

onAttachedToHost

Added in 1.1.0
public void onAttachedToHost(@NonNull PlaybackGlueHost host)

This method is called attached to associated PlaybackGlueHost.

Parameters
@NonNull PlaybackGlueHost host

onDetachedFromHost

Added in 1.1.0
public void onDetachedFromHost()

This method is called when current associated PlaybackGlueHost is attached to a different PlaybackGlue or PlaybackGlueHost is destroyed. Subclass may override. A typical implementation will release resources (e.g. MediaPlayer or connection to playback service) in this method.

pause

Added in 1.1.0
public abstract void pause()

Pauses the media player.

play

Added in 1.1.0
public abstract void play()

Starts the media player.

previous

Added in 1.1.0
public void previous()

Optional method. Override this method if getSupportedActions include ACTION_SKIP_TO_PREVIOUS to skip to previous item.

rewind

Added in 1.1.0
public void rewind()

Optional method. Override this method if getSupportedActions include ACTION_REWIND to rewind in current media item.

seekTo

Added in 1.1.0
public void seekTo(long positionInMs)

Seek to new position.

Parameters
long positionInMs

New position in milliseconds.

setCallback

Added in 1.1.0
public final void setCallback(@Nullable PlayerAdapter.Callback callback)

Sets callback for event of PlayerAdapter.

Parameters
@Nullable PlayerAdapter.Callback callback

Client for event of PlayerAdapter.

setProgressUpdatingEnabled

Added in 1.1.0
public void setProgressUpdatingEnabled(boolean enable)

Implement this method to enable or disable progress updating.

Parameters
boolean enable

True to enable progress updating, false otherwise.

setRepeatAction

Added in 1.1.0
public void setRepeatAction(int repeatActionIndex)

Optional method. Override this method if getSupportedActions include ACTION_REPEAT to set the repeat action.

Parameters
int repeatActionIndex

The shuffle action. Must be one of the followings: INDEX_ONEINDEX_ALL, INDEX_NONE,

setShuffleAction

Added in 1.1.0
public void setShuffleAction(int shuffleActionIndex)

Optional method. Override this method if getSupportedActions include ACTION_SHUFFLE to set the shuffle action.

Parameters
int shuffleActionIndex

The repeat action. Must be one of the followings: INDEX_OFFINDEX_ON