public final class PlaybackStateCompat extends Object implements Parcelable
MediaSessionCompat
. This includes a state like
STATE_PLAYING
, the current playback position,
and the current control capabilities.Modifier and Type | Class and Description |
---|---|
static interface |
PlaybackStateCompat.Actions |
static class |
PlaybackStateCompat.Builder
Builder for
PlaybackStateCompat objects. |
static class |
PlaybackStateCompat.CustomAction
CustomActions can be used to
extend the capabilities of the standard transport controls by exposing
app specific actions to Controllers . |
static interface |
PlaybackStateCompat.MediaKeyAction |
static interface |
PlaybackStateCompat.State |
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static long |
ACTION_FAST_FORWARD
Indicates this session supports the fast forward command.
|
static long |
ACTION_PAUSE
Indicates this session supports the pause command.
|
static long |
ACTION_PLAY
Indicates this session supports the play command.
|
static long |
ACTION_PLAY_FROM_MEDIA_ID
Indicates this session supports the play from media id command.
|
static long |
ACTION_PLAY_FROM_SEARCH
Indicates this session supports the play from search command.
|
static long |
ACTION_PLAY_FROM_URI
Indicates this session supports the play from URI command.
|
static long |
ACTION_PLAY_PAUSE
Indicates this session supports the play/pause toggle command.
|
static long |
ACTION_PREPARE
Indicates this session supports the prepare command.
|
static long |
ACTION_PREPARE_FROM_MEDIA_ID
Indicates this session supports the prepare from media id command.
|
static long |
ACTION_PREPARE_FROM_SEARCH
Indicates this session supports the prepare from search command.
|
static long |
ACTION_PREPARE_FROM_URI
Indicates this session supports the prepare from URI command.
|
static long |
ACTION_REWIND
Indicates this session supports the rewind command.
|
static long |
ACTION_SEEK_TO
Indicates this session supports the seek to command.
|
static long |
ACTION_SET_RATING
Indicates this session supports the set rating command.
|
static long |
ACTION_SKIP_TO_NEXT
Indicates this session supports the next command.
|
static long |
ACTION_SKIP_TO_PREVIOUS
Indicates this session supports the previous command.
|
static long |
ACTION_SKIP_TO_QUEUE_ITEM
Indicates this session supports the skip to queue item command.
|
static long |
ACTION_STOP
Indicates this session supports the stop command.
|
static Parcelable.Creator<PlaybackStateCompat> |
CREATOR |
static long |
PLAYBACK_POSITION_UNKNOWN
Use this value for the position to indicate the position is not known.
|
static int |
STATE_BUFFERING
State indicating this item is currently buffering and will begin playing
when enough data has buffered.
|
static int |
STATE_CONNECTING
State indicating the class doing playback is currently connecting to a
route.
|
static int |
STATE_ERROR
State indicating this item is currently in an error state.
|
static int |
STATE_FAST_FORWARDING
State indicating this item is currently fast forwarding.
|
static int |
STATE_NONE
This is the default playback state and indicates that no media has been
added yet, or the performer has been reset and has no content to play.
|
static int |
STATE_PAUSED
State indicating this item is currently paused.
|
static int |
STATE_PLAYING
State indicating this item is currently playing.
|
static int |
STATE_REWINDING
State indicating this item is currently rewinding.
|
static int |
STATE_SKIPPING_TO_NEXT
State indicating the player is currently skipping to the next item.
|
static int |
STATE_SKIPPING_TO_PREVIOUS
State indicating the player is currently skipping to the previous item.
|
static int |
STATE_SKIPPING_TO_QUEUE_ITEM
State indicating the player is currently skipping to a specific item in
the queue.
|
static int |
STATE_STOPPED
State indicating this item is currently stopped.
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Modifier and Type | Method and Description |
---|---|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
static PlaybackStateCompat |
fromPlaybackState(Object stateObj)
Creates an instance from a framework
PlaybackState object. |
long |
getActions()
Get the current actions available on this session.
|
long |
getActiveQueueItemId()
Get the id of the currently active item in the queue.
|
long |
getBufferedPosition()
Get the current buffered position in ms.
|
List<PlaybackStateCompat.CustomAction> |
getCustomActions()
Get the list of custom actions.
|
CharSequence |
getErrorMessage()
Get a user readable error message.
|
Bundle |
getExtras()
Get any custom extras that were set on this playback state.
|
long |
getLastPositionUpdateTime()
Get the elapsed real time at which position was last updated.
|
float |
getPlaybackSpeed()
Get the current playback speed as a multiple of normal playback.
|
Object |
getPlaybackState()
Gets the underlying framework
PlaybackState object. |
long |
getPosition()
Get the current playback position in ms.
|
int |
getState()
Get the current state of playback.
|
static int |
toKeyCode(long action)
Translates a given action into a matched key code defined in
KeyEvent . |
String |
toString()
Returns a string representation of the object.
|
void |
writeToParcel(Parcel dest,
int flags)
Flatten this object in to a Parcel.
|
public static final long ACTION_STOP
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_PAUSE
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_PLAY
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_REWIND
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_SKIP_TO_PREVIOUS
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_SKIP_TO_NEXT
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_FAST_FORWARD
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_SET_RATING
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_SEEK_TO
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_PLAY_PAUSE
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_PLAY_FROM_MEDIA_ID
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_PLAY_FROM_SEARCH
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_SKIP_TO_QUEUE_ITEM
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_PLAY_FROM_URI
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_PREPARE
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_PREPARE_FROM_MEDIA_ID
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_PREPARE_FROM_SEARCH
Builder#setActions(long)
,
Constant Field Valuespublic static final long ACTION_PREPARE_FROM_URI
Builder#setActions(long)
,
Constant Field Valuespublic static final int STATE_NONE
Builder#setState
,
Constant Field Valuespublic static final int STATE_STOPPED
Builder#setState
,
Constant Field Valuespublic static final int STATE_PAUSED
Builder#setState
,
Constant Field Valuespublic static final int STATE_PLAYING
Builder#setState
,
Constant Field Valuespublic static final int STATE_FAST_FORWARDING
Builder#setState
,
Constant Field Valuespublic static final int STATE_REWINDING
Builder#setState
,
Constant Field Valuespublic static final int STATE_BUFFERING
Builder#setState
,
Constant Field Valuespublic static final int STATE_ERROR
Builder#setState
,
Constant Field Valuespublic static final int STATE_CONNECTING
STATE_NONE
. If
the connection failed STATE_ERROR
should be used.
On devices earlier than API 21, this will appear as STATE_BUFFERING
Builder#setState
,
Constant Field Valuespublic static final int STATE_SKIPPING_TO_PREVIOUS
Builder#setState
,
Constant Field Valuespublic static final int STATE_SKIPPING_TO_NEXT
Builder#setState
,
Constant Field Valuespublic static final int STATE_SKIPPING_TO_QUEUE_ITEM
On devices earlier than API 21, this will appear as STATE_SKIPPING_TO_NEXT
Builder#setState
,
Constant Field Valuespublic static final long PLAYBACK_POSITION_UNKNOWN
public static final Parcelable.Creator<PlaybackStateCompat> CREATOR
public static int toKeyCode(long action)
KeyEvent
. The given
action should be one of the following:
action
- The action to be translated.public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
public int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel dest, int flags)
Parcelable
writeToParcel
in interface Parcelable
dest
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.public int getState()
public long getPosition()
public long getBufferedPosition()
public float getPlaybackSpeed()
public long getActions()
ACTION_SKIP_TO_PREVIOUS
ACTION_REWIND
ACTION_PLAY
ACTION_PLAY_PAUSE
ACTION_PAUSE
ACTION_STOP
ACTION_FAST_FORWARD
ACTION_SKIP_TO_NEXT
ACTION_SEEK_TO
ACTION_SET_RATING
ACTION_PLAY_FROM_MEDIA_ID
ACTION_PLAY_FROM_SEARCH
ACTION_SKIP_TO_QUEUE_ITEM
ACTION_PLAY_FROM_URI
ACTION_PREPARE
ACTION_PREPARE_FROM_MEDIA_ID
ACTION_PREPARE_FROM_SEARCH
ACTION_PREPARE_FROM_URI
public List<PlaybackStateCompat.CustomAction> getCustomActions()
public CharSequence getErrorMessage()
STATE_ERROR
.public long getLastPositionUpdateTime()
public long getActiveQueueItemId()
MediaSessionCompat.QueueItem.UNKNOWN_ID
.MediaSessionCompat.QueueItem.UNKNOWN_ID
.@Nullable public Bundle getExtras()
public static PlaybackStateCompat fromPlaybackState(Object stateObj)
PlaybackState
object.
This method is only supported on API 21+.
stateObj
- A PlaybackState
object, or null if none.PlaybackStateCompat
object, or null if none.public Object getPlaybackState()
PlaybackState
object.
This method is only supported on API 21+.
PlaybackState
object, or null if none.