LeanbackPlayerAdapter


@UnstableApi
public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnable


Leanback PlayerAdapter implementation for Player.

Summary

Public constructors

LeanbackPlayerAdapter(
    Context context,
    Player player,
    int updatePeriodMs
)

Builds an instance.

Public methods

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.

boolean

Returns true if media is currently playing.

boolean
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
run()
void
seekTo(long positionInMs)

Seek to new position.

void

Sets the optional ErrorMessageProvider.

void

Implement this method to enable or disable progress updating.

Inherited methods

From androidx.leanback.media.PlayerAdapter
void

Optional method.

final @Nullable PlayerAdapter.Callback

Gets callback for event of PlayerAdapter.

long

Return xor combination of values defined in PlaybackBaseControlGlue.

void

Optional method.

void

Optional method.

void

Optional method.

final void

Sets callback for event of PlayerAdapter.

void
setRepeatAction(int repeatActionIndex)

Optional method.

void
setShuffleAction(int shuffleActionIndex)

Optional method.

Public constructors

LeanbackPlayerAdapter

public LeanbackPlayerAdapter(
    Context context,
    Player player,
    int updatePeriodMs
)

Builds an instance. Note that the PlayerAdapter does not manage the lifecycle of the Player instance. The caller remains responsible for releasing the player when it's no longer required.

Parameters
Context context

The current Context (activity).

Player player

The Player being used.

int updatePeriodMs

The delay between player control updates, in milliseconds.

Public methods

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.

isPlaying

public boolean isPlaying()

Returns true if media is currently playing.

isPrepared

public boolean isPrepared()
Returns
boolean

True if media is ready for playback, false otherwise.

onAttachedToHost

public void onAttachedToHost(PlaybackGlueHost host)

This method is called attached to associated PlaybackGlueHost.

Parameters
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

public void pause()

Pauses the media player.

play

public void play()

Starts the media player.

run

public void run()

seekTo

public void seekTo(long positionInMs)

Seek to new position.

Parameters
long positionInMs

New position in milliseconds.

setErrorMessageProvider

public void setErrorMessageProvider(
    @Nullable ErrorMessageProvider<PlaybackException> errorMessageProvider
)

Sets the optional ErrorMessageProvider.

Parameters
@Nullable ErrorMessageProvider<PlaybackException> errorMessageProvider

The ErrorMessageProvider.

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.