LeanbackPlayerAdapter


@UnstableApi
class LeanbackPlayerAdapter : PlayerAdapter, Runnable


Leanback PlayerAdapter implementation for Player.

Summary

Public constructors

LeanbackPlayerAdapter(
    context: Context!,
    player: Player!,
    updatePeriodMs: Int
)

Builds an instance.

Public functions

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
Unit

This method is called attached to associated PlaybackGlueHost.

Unit

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

Unit

Pauses the media player.

Unit

Starts the media player.

Unit
run()
Unit
seekTo(positionInMs: Long)

Seek to new position.

Unit

Sets the optional ErrorMessageProvider.

Unit

Implement this method to enable or disable progress updating.

Inherited functions

From androidx.leanback.media.PlayerAdapter
Unit

Optional method.

PlayerAdapter.Callback?

Gets callback for event of PlayerAdapter.

Long

Return xor combination of values defined in PlaybackBaseControlGlue.

Unit

Optional method.

Unit

Optional method.

Unit

Optional method.

Unit

Sets callback for event of PlayerAdapter.

Unit
setRepeatAction(repeatActionIndex: Int)

Optional method.

Unit
setShuffleAction(shuffleActionIndex: Int)

Optional method.

Public constructors

LeanbackPlayerAdapter

LeanbackPlayerAdapter(
    context: Context!,
    player: Player!,
    updatePeriodMs: Int
)

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.

updatePeriodMs: Int

The delay between player control updates, in milliseconds.

Public functions

getBufferedPosition

fun getBufferedPosition(): Long

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

getCurrentPosition

fun getCurrentPosition(): Long

Returns the current position of the media item in milliseconds.

getDuration

fun getDuration(): Long

Returns the duration of the media item in milliseconds.

isPlaying

fun isPlaying(): Boolean

Returns true if media is currently playing.

isPrepared

fun isPrepared(): Boolean
Returns
Boolean

True if media is ready for playback, false otherwise.

onAttachedToHost

fun onAttachedToHost(host: PlaybackGlueHost!): Unit

This method is called attached to associated PlaybackGlueHost.

Parameters
host: PlaybackGlueHost!

onDetachedFromHost

fun onDetachedFromHost(): Unit

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

fun pause(): Unit

Pauses the media player.

play

fun play(): Unit

Starts the media player.

run

fun run(): Unit

seekTo

fun seekTo(positionInMs: Long): Unit

Seek to new position.

Parameters
positionInMs: Long

New position in milliseconds.

setErrorMessageProvider

fun setErrorMessageProvider(
    errorMessageProvider: ErrorMessageProvider<PlaybackException!>?
): Unit

Sets the optional ErrorMessageProvider.

Parameters
errorMessageProvider: ErrorMessageProvider<PlaybackException!>?

The ErrorMessageProvider.

setProgressUpdatingEnabled

fun setProgressUpdatingEnabled(enable: Boolean): Unit

Implement this method to enable or disable progress updating.

Parameters
enable: Boolean

True to enable progress updating, false otherwise.