MediaControllerAdapter

public class MediaControllerAdapter extends PlayerAdapter


A helper class for implementing a adapter layer for MediaControllerCompat.

Summary

Public constructors

Constructor for the adapter using MediaControllerCompat.

Public methods

void

Optional method.

long

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

long

Returns the current position of the media item in milliseconds.

long

Returns the duration of the media item in milliseconds.

Drawable

Get current media's drawable art.

MediaControllerCompat

Return the object of MediaControllerCompat from this class.

CharSequence

Get current media's subtitle.

CharSequence

Get current media's title.

long

Return xor combination of values defined in PlaybackBaseControlGlue.

boolean

Returns true if media is currently playing.

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.

void

Pauses the media player.

void

Starts the media player.

void

Optional method.

void

Optional method.

void
seekTo(long positionInMs)

Seek to new position.

void

Implement this method to enable or disable progress updating.

void
setRepeatAction(int repeatActionIndex)

Optional method.

void
setShuffleAction(int shuffleActionIndex)

Optional method.

Inherited methods

From androidx.leanback.media.PlayerAdapter
final @Nullable PlayerAdapter.Callback

Gets callback for event of PlayerAdapter.

boolean
final void

Sets callback for event of PlayerAdapter.

Public constructors

MediaControllerAdapter

Added in 1.1.0
public MediaControllerAdapter(MediaControllerCompat controller)

Constructor for the adapter using MediaControllerCompat.

Parameters
MediaControllerCompat controller

Object of MediaControllerCompat..

Public methods

fastForward

public void fastForward()

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

getBufferedPosition

public long getBufferedPosition()

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

getCurrentPosition

public long getCurrentPosition()

Returns the current position of the media item in milliseconds.

getDuration

public long getDuration()

Returns the duration of the media item in milliseconds.

getMediaArt

Added in 1.1.0
public Drawable getMediaArt(Context context)

Get current media's drawable art.

Returns
Drawable

Drawable art of current media.

getMediaController

Added in 1.1.0
public MediaControllerCompat getMediaController()

Return the object of MediaControllerCompat from this class.

Returns
MediaControllerCompat

Media Controller Compat object owned by this class.

getMediaSubtitle

Added in 1.1.0
public CharSequence getMediaSubtitle()

Get current media's subtitle.

Returns
CharSequence

Subtitle of current media.

getMediaTitle

Added in 1.1.0
public CharSequence getMediaTitle()

Get current media's title.

Returns
CharSequence

Title of current media.

getSupportedActions

public long getSupportedActions()

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

isPlaying

public boolean isPlaying()

Returns true if media is currently playing.

next

public void next()

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

onAttachedToHost

public void onAttachedToHost(@NonNull PlaybackGlueHost host)

This method is called attached to associated PlaybackGlueHost.

Parameters
@NonNull PlaybackGlueHost host

onDetachedFromHost

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.2.0-alpha04
public void pause()

Pauses the media player.

play

Added in 1.2.0-alpha04
public void play()

Starts the media player.

previous

public void previous()

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

rewind

public void rewind()

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

seekTo

public void seekTo(long positionInMs)

Seek to new position.

Parameters
long positionInMs

New position in milliseconds.

setProgressUpdatingEnabled

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

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

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