PlayerAdapter
public
abstract
class
PlayerAdapter
extends Object
java.lang.Object | |
↳ | androidx.leanback.media.PlayerAdapter |
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 MediaPlayer
.
ExoPlayer also provides a leanback extension that implements PlayerAdapter. Please see
ExoPlayer
https://developer.android.com/guide/topics/media/exoplayer
Summary
Nested classes | |
---|---|
class |
PlayerAdapter.Callback
Client for client of PlayerAdapter. |
Public constructors | |
---|---|
PlayerAdapter()
|
Public methods | |
---|---|
void
|
fastForward()
Optional method. |
long
|
getBufferedPosition()
Returns the current buffered position of the media item in milliseconds. |
final
PlayerAdapter.Callback
|
getCallback()
Gets callback for event of PlayerAdapter. |
long
|
getCurrentPosition()
Returns the current position of the media item in milliseconds. |
long
|
getDuration()
Returns the duration of the media item in milliseconds. |
long
|
getSupportedActions()
Return xor combination of values defined in PlaybackBaseControlGlue. |
boolean
|
isPlaying()
Returns true if media is currently playing. |
boolean
|
isPrepared()
|
void
|
next()
Optional method. |
void
|
onAttachedToHost(PlaybackGlueHost host)
This method is called attached to associated |
void
|
onDetachedFromHost()
This method is called when current associated |
abstract
void
|
pause()
Pauses the media player. |
abstract
void
|
play()
Starts the media player. |
void
|
previous()
Optional method. |
void
|
rewind()
Optional method. |
void
|
seekTo(long positionInMs)
Seek to new position. |
final
void
|
setCallback(PlayerAdapter.Callback callback)
Sets callback for event of PlayerAdapter. |
void
|
setProgressUpdatingEnabled(boolean enable)
Implement this method to enable or disable progress updating. |
void
|
setRepeatAction(int repeatActionIndex)
Optional method. |
void
|
setShuffleAction(int shuffleActionIndex)
Optional method. |
Inherited methods | |
---|---|
Public constructors
PlayerAdapter
public PlayerAdapter ()
Public methods
fastForward
public void fastForward ()
Optional method. Override this method if getSupportedActions()
include
PlaybackBaseControlGlue.ACTION_FAST_FORWARD
to fast
forward current media item.
getBufferedPosition
public long getBufferedPosition ()
Returns the current buffered position of the media item in milliseconds.
Returns | |
---|---|
long |
getCallback
public final PlayerAdapter.Callback getCallback ()
Gets callback for event of PlayerAdapter.
Returns | |
---|---|
PlayerAdapter.Callback |
Client for event of PlayerAdapter. |
getCurrentPosition
public long getCurrentPosition ()
Returns the current position of the media item in milliseconds.
Returns | |
---|---|
long |
getDuration
public long getDuration ()
Returns the duration of the media item in milliseconds.
Returns | |
---|---|
long |
getSupportedActions
public long getSupportedActions ()
Return xor combination of values defined in PlaybackBaseControlGlue. Default is PLAY_PAUSE (unless subclass enforce to be 0)
Returns | |
---|---|
long |
isPlaying
public boolean isPlaying ()
Returns true if media is currently playing.
Returns | |
---|---|
boolean |
isPrepared
public boolean isPrepared ()
Returns | |
---|---|
boolean |
True if media is ready for playback, false otherwise. |
next
public void next ()
Optional method. Override this method if getSupportedActions()
include
PlaybackBaseControlGlue.ACTION_SKIP_TO_NEXT
to skip
to next item.
onAttachedToHost
public void onAttachedToHost (PlaybackGlueHost host)
This method is called attached to associated PlaybackGlueHost
.
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 abstract void pause ()
Pauses the media player.
play
public abstract void play ()
Starts the media player.
previous
public void previous ()
Optional method. Override this method if getSupportedActions()
include
PlaybackBaseControlGlue.ACTION_SKIP_TO_PREVIOUS
to skip
to previous item.
rewind
public void rewind ()
Optional method. Override this method if getSupportedActions()
include
PlaybackBaseControlGlue.ACTION_REWIND
to rewind in
current media item.
seekTo
public void seekTo (long positionInMs)
Seek to new position.
Parameters | |
---|---|
positionInMs |
long : New position in milliseconds.
|
setCallback
public final void setCallback (PlayerAdapter.Callback callback)
Sets callback for event of PlayerAdapter.
Parameters | |
---|---|
callback |
PlayerAdapter.Callback : Client for event of PlayerAdapter.
|
setProgressUpdatingEnabled
public void setProgressUpdatingEnabled (boolean enable)
Implement this method to enable or disable progress updating.
Parameters | |
---|---|
enable |
boolean : True to enable progress updating, false otherwise.
|
setRepeatAction
public void setRepeatAction (int repeatActionIndex)
Optional method. Override this method if getSupportedActions()
include
PlaybackBaseControlGlue.ACTION_REPEAT
to set the repeat action.
Parameters | |
---|---|
repeatActionIndex |
int : The shuffle action. Must be one of the followings:
PlaybackControlsRow.RepeatAction.INDEX_ONE
PlaybackControlsRow.RepeatAction.INDEX_ALL ,
PlaybackControlsRow.RepeatAction.INDEX_NONE ,
|
setShuffleAction
public void setShuffleAction (int shuffleActionIndex)
Optional method. Override this method if getSupportedActions()
include
PlaybackBaseControlGlue.ACTION_SHUFFLE
to set the shuffle action.
Parameters | |
---|---|
shuffleActionIndex |
int : The repeat action. Must be one of the followings:
PlaybackControlsRow.ShuffleAction.INDEX_OFF
PlaybackControlsRow.ShuffleAction.INDEX_ON
|
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-09-30 UTC.