PlaybackState
public
final
class
PlaybackState
extends Object
implements
Parcelable
java.lang.Object | |
↳ | android.media.session.PlaybackState |
Playback state for a MediaSession
. This includes a state like
PlaybackState#STATE_PLAYING
, the current playback position,
and the current control capabilities.
Summary
Nested classes | |
---|---|
class |
PlaybackState.Builder
Builder for |
class |
PlaybackState.CustomAction
|
Constants | |
---|---|
long |
ACTION_FAST_FORWARD
Indicates this session supports the fast forward command. |
long |
ACTION_PAUSE
Indicates this session supports the pause command. |
long |
ACTION_PLAY
Indicates this session supports the play command. |
long |
ACTION_PLAY_FROM_MEDIA_ID
Indicates this session supports the play from media id command. |
long |
ACTION_PLAY_FROM_SEARCH
Indicates this session supports the play from search command. |
long |
ACTION_PLAY_FROM_URI
Indicates this session supports the play from URI command. |
long |
ACTION_PLAY_PAUSE
Indicates this session supports the play/pause toggle command. |
long |
ACTION_PREPARE
Indicates this session supports the prepare command. |
long |
ACTION_PREPARE_FROM_MEDIA_ID
Indicates this session supports the prepare from media id command. |
long |
ACTION_PREPARE_FROM_SEARCH
Indicates this session supports the prepare from search command. |
long |
ACTION_PREPARE_FROM_URI
Indicates this session supports the prepare from URI command. |
long |
ACTION_REWIND
Indicates this session supports the rewind command. |
long |
ACTION_SEEK_TO
Indicates this session supports the seek to command. |
long |
ACTION_SET_PLAYBACK_SPEED
Indicates this session supports the set playback speed command. |
long |
ACTION_SET_RATING
Indicates this session supports the set rating command. |
long |
ACTION_SKIP_TO_NEXT
Indicates this session supports the next command. |
long |
ACTION_SKIP_TO_PREVIOUS
Indicates this session supports the previous command. |
long |
ACTION_SKIP_TO_QUEUE_ITEM
Indicates this session supports the skip to queue item command. |
long |
ACTION_STOP
Indicates this session supports the stop command. |
long |
PLAYBACK_POSITION_UNKNOWN
Use this value for the position to indicate the position is not known. |
int |
STATE_BUFFERING
State indicating this item is currently buffering and will begin playing when enough data has buffered. |
int |
STATE_CONNECTING
State indicating the class doing playback is currently connecting to a new destination. |
int |
STATE_ERROR
State indicating this item is currently in an error state. |
int |
STATE_FAST_FORWARDING
State indicating this item is currently fast forwarding. |
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. |
int |
STATE_PAUSED
State indicating this item is currently paused. |
int |
STATE_PLAYING
State indicating this item is currently playing. |
int |
STATE_REWINDING
State indicating this item is currently rewinding. |
int |
STATE_SKIPPING_TO_NEXT
State indicating the player is currently skipping to the next item. |
int |
STATE_SKIPPING_TO_PREVIOUS
State indicating the player is currently skipping to the previous item. |
int |
STATE_SKIPPING_TO_QUEUE_ITEM
State indicating the player is currently skipping to a specific item in the queue. |
int |
STATE_STOPPED
State indicating this item is currently stopped. |
Inherited constants |
---|
Fields | |
---|---|
public
static
final
Creator<PlaybackState> |
CREATOR
|
Public methods | |
---|---|
int
|
describeContents()
Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
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<PlaybackState.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. |
long
|
getPosition()
Get the current playback position in ms. |
int
|
getState()
Get the current state of playback. |
boolean
|
isActive()
Returns whether this is considered as an active playback state. |
String
|
toString()
Returns a string representation of the object. |
void
|
writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel. |
Inherited methods | |
---|---|
Constants
ACTION_FAST_FORWARD
public static final long ACTION_FAST_FORWARD
Indicates this session supports the fast forward command.
See also:
Constant Value: 64 (0x0000000000000040)
ACTION_PAUSE
public static final long ACTION_PAUSE
Indicates this session supports the pause command.
See also:
Constant Value: 2 (0x0000000000000002)
ACTION_PLAY
public static final long ACTION_PLAY
Indicates this session supports the play command.
See also:
Constant Value: 4 (0x0000000000000004)
ACTION_PLAY_FROM_MEDIA_ID
public static final long ACTION_PLAY_FROM_MEDIA_ID
Indicates this session supports the play from media id command.
See also:
Constant Value: 1024 (0x0000000000000400)
ACTION_PLAY_FROM_SEARCH
public static final long ACTION_PLAY_FROM_SEARCH
Indicates this session supports the play from search command.
See also:
Constant Value: 2048 (0x0000000000000800)
ACTION_PLAY_FROM_URI
public static final long ACTION_PLAY_FROM_URI
Indicates this session supports the play from URI command.
See also:
Constant Value: 8192 (0x0000000000002000)
ACTION_PLAY_PAUSE
public static final long ACTION_PLAY_PAUSE
Indicates this session supports the play/pause toggle command.
See also:
Constant Value: 512 (0x0000000000000200)
ACTION_PREPARE
public static final long ACTION_PREPARE
Indicates this session supports the prepare command.
See also:
Constant Value: 16384 (0x0000000000004000)
ACTION_PREPARE_FROM_MEDIA_ID
public static final long ACTION_PREPARE_FROM_MEDIA_ID
Indicates this session supports the prepare from media id command.
See also:
Constant Value: 32768 (0x0000000000008000)
ACTION_PREPARE_FROM_SEARCH
public static final long ACTION_PREPARE_FROM_SEARCH
Indicates this session supports the prepare from search command.
See also:
Constant Value: 65536 (0x0000000000010000)
ACTION_PREPARE_FROM_URI
public static final long ACTION_PREPARE_FROM_URI
Indicates this session supports the prepare from URI command.
See also:
Constant Value: 131072 (0x0000000000020000)
ACTION_REWIND
public static final long ACTION_REWIND
Indicates this session supports the rewind command.
See also:
Constant Value: 8 (0x0000000000000008)
ACTION_SEEK_TO
public static final long ACTION_SEEK_TO
Indicates this session supports the seek to command.
See also:
Constant Value: 256 (0x0000000000000100)
ACTION_SET_PLAYBACK_SPEED
public static final long ACTION_SET_PLAYBACK_SPEED
Indicates this session supports the set playback speed command.
See also:
Constant Value: 4194304 (0x0000000000400000)
ACTION_SET_RATING
public static final long ACTION_SET_RATING
Indicates this session supports the set rating command.
See also:
Constant Value: 128 (0x0000000000000080)
ACTION_SKIP_TO_NEXT
public static final long ACTION_SKIP_TO_NEXT
Indicates this session supports the next command.
See also:
Constant Value: 32 (0x0000000000000020)
ACTION_SKIP_TO_PREVIOUS
public static final long ACTION_SKIP_TO_PREVIOUS
Indicates this session supports the previous command.
See also:
Constant Value: 16 (0x0000000000000010)
ACTION_SKIP_TO_QUEUE_ITEM
public static final long ACTION_SKIP_TO_QUEUE_ITEM
Indicates this session supports the skip to queue item command.
See also:
Constant Value: 4096 (0x0000000000001000)
ACTION_STOP
public static final long ACTION_STOP
Indicates this session supports the stop command.
See also:
Constant Value: 1 (0x0000000000000001)
PLAYBACK_POSITION_UNKNOWN
public static final long PLAYBACK_POSITION_UNKNOWN
Use this value for the position to indicate the position is not known.
Constant Value: -1 (0xffffffffffffffff)
STATE_BUFFERING
public static final int STATE_BUFFERING
State indicating this item is currently buffering and will begin playing when enough data has buffered.
Constant Value: 6 (0x00000006)
STATE_CONNECTING
public static final int STATE_CONNECTING
State indicating the class doing playback is currently connecting to a
new destination. Depending on the implementation you may return to the previous
state when the connection finishes or enter STATE_NONE
.
If the connection failed STATE_ERROR
should be used.
Constant Value: 8 (0x00000008)
STATE_ERROR
public static final int STATE_ERROR
State indicating this item is currently in an error state. The error message should also be set when entering this state.
Constant Value: 7 (0x00000007)
STATE_FAST_FORWARDING
public static final int STATE_FAST_FORWARDING
State indicating this item is currently fast forwarding.
Constant Value: 4 (0x00000004)
STATE_NONE
public static final 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.
See also:
Constant Value: 0 (0x00000000)
STATE_PAUSED
public static final int STATE_PAUSED
State indicating this item is currently paused.
Constant Value: 2 (0x00000002)
STATE_PLAYING
public static final int STATE_PLAYING
State indicating this item is currently playing.
Constant Value: 3 (0x00000003)
STATE_REWINDING
public static final int STATE_REWINDING
State indicating this item is currently rewinding.
Constant Value: 5 (0x00000005)
STATE_SKIPPING_TO_NEXT
public static final int STATE_SKIPPING_TO_NEXT
State indicating the player is currently skipping to the next item.
Constant Value: 10 (0x0000000a)
STATE_SKIPPING_TO_PREVIOUS
public static final int STATE_SKIPPING_TO_PREVIOUS
State indicating the player is currently skipping to the previous item.
Constant Value: 9 (0x00000009)
STATE_SKIPPING_TO_QUEUE_ITEM
public static final int STATE_SKIPPING_TO_QUEUE_ITEM
State indicating the player is currently skipping to a specific item in the queue.
Constant Value: 11 (0x0000000b)
STATE_STOPPED
public static final int STATE_STOPPED
State indicating this item is currently stopped.
Constant Value: 1 (0x00000001)
Fields
Public methods
describeContents
public int describeContents ()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation. For example, if the object will
include a file descriptor in the output of writeToParcel(android.os.Parcel, int)
,
the return value of this method must include the
CONTENTS_FILE_DESCRIPTOR
bit.
Returns | |
---|---|
int |
a bitmask indicating the set of special object types marshaled
by this Parcelable object instance.
Value is either 0 or CONTENTS_FILE_DESCRIPTOR |
getActions
public long getActions ()
Get the current actions available on this session. This should use a bitmask of the available actions.
-
PlaybackState#ACTION_SKIP_TO_PREVIOUS
-
PlaybackState#ACTION_REWIND
-
PlaybackState#ACTION_PLAY
-
PlaybackState#ACTION_PAUSE
-
PlaybackState#ACTION_STOP
-
PlaybackState#ACTION_FAST_FORWARD
-
PlaybackState#ACTION_SKIP_TO_NEXT
-
PlaybackState#ACTION_SEEK_TO
-
PlaybackState#ACTION_SET_RATING
-
PlaybackState#ACTION_PLAY_PAUSE
-
PlaybackState#ACTION_PLAY_FROM_MEDIA_ID
-
PlaybackState#ACTION_PLAY_FROM_SEARCH
-
PlaybackState#ACTION_SKIP_TO_QUEUE_ITEM
-
PlaybackState#ACTION_PLAY_FROM_URI
-
PlaybackState#ACTION_PREPARE
-
PlaybackState#ACTION_PREPARE_FROM_MEDIA_ID
-
PlaybackState#ACTION_PREPARE_FROM_SEARCH
-
PlaybackState#ACTION_PREPARE_FROM_URI
-
PlaybackState#ACTION_SET_PLAYBACK_SPEED
getActiveQueueItemId
public long getActiveQueueItemId ()
Get the id of the currently active item in the queue. If there is no
queue or a queue is not supported by the session this will be
MediaSession.QueueItem#UNKNOWN_ID
.
Returns | |
---|---|
long |
The id of the currently active item in the queue or
MediaSession.QueueItem#UNKNOWN_ID . |
getBufferedPosition
public long getBufferedPosition ()
Get the current buffered position in ms. This is the farthest playback point that can be reached from the current position using only buffered content.
Returns | |
---|---|
long |
getCustomActions
public List<PlaybackState.CustomAction> getCustomActions ()
Get the list of custom actions.
Returns | |
---|---|
List<PlaybackState.CustomAction> |
getErrorMessage
public CharSequence getErrorMessage ()
Get a user readable error message. This should be set when the state is
PlaybackState#STATE_ERROR
.
Returns | |
---|---|
CharSequence |
getExtras
public Bundle getExtras ()
Get any custom extras that were set on this playback state.
Returns | |
---|---|
Bundle |
The extras for this state or null. |
getLastPositionUpdateTime
public long getLastPositionUpdateTime ()
Get the elapsed real time at which position was last updated. If the position has never been set this will return 0;
Returns | |
---|---|
long |
The last time the position was updated. |
getPlaybackSpeed
public float getPlaybackSpeed ()
Get the current playback speed as a multiple of normal playback. This should be negative when rewinding. A value of 1 means normal playback and 0 means paused.
Returns | |
---|---|
float |
The current speed of playback. |
getPosition
public long getPosition ()
Get the current playback position in ms.
Returns | |
---|---|
long |
getState
public int getState ()
Get the current state of playback. One of the following:
-
PlaybackState#STATE_NONE
-
PlaybackState#STATE_STOPPED
-
PlaybackState#STATE_PLAYING
-
PlaybackState#STATE_PAUSED
-
PlaybackState#STATE_FAST_FORWARDING
-
PlaybackState#STATE_REWINDING
-
PlaybackState#STATE_BUFFERING
-
PlaybackState#STATE_ERROR
-
PlaybackState#STATE_CONNECTING
-
PlaybackState#STATE_SKIPPING_TO_PREVIOUS
-
PlaybackState#STATE_SKIPPING_TO_NEXT
-
PlaybackState#STATE_SKIPPING_TO_QUEUE_ITEM
-
ERROR(PlaybackState#STATE_PLAYBACK_SUPPRESSED/android.media.session.PlaybackState#STATE_PLAYBACK_SUPPRESSED PlaybackState#STATE_PLAYBACK_SUPPRESSED)
Returns | |
---|---|
int |
Value is STATE_NONE , STATE_STOPPED , STATE_PAUSED , STATE_PLAYING , STATE_FAST_FORWARDING , STATE_REWINDING , STATE_BUFFERING , STATE_ERROR , STATE_CONNECTING , STATE_SKIPPING_TO_PREVIOUS , STATE_SKIPPING_TO_NEXT , STATE_SKIPPING_TO_QUEUE_ITEM , or android.media.session.PlaybackState.STATE_PLAYBACK_SUPPRESSED |
isActive
public boolean isActive ()
Returns whether this is considered as an active playback state.
The playback state is considered as an active if the state is one of the following:
STATE_BUFFERING
STATE_CONNECTING
STATE_FAST_FORWARDING
STATE_PLAYING
STATE_REWINDING
STATE_SKIPPING_TO_NEXT
STATE_SKIPPING_TO_PREVIOUS
STATE_SKIPPING_TO_QUEUE_ITEM
ERROR(/#STATE_PLAYBACK_SUPPRESSED)
Returns | |
---|---|
boolean |
toString
public String toString ()
Returns a string representation of the object.
Returns | |
---|---|
String |
a string representation of the object. |
writeToParcel
public void writeToParcel (Parcel dest, int flags)
Flatten this object in to a Parcel.
Parameters | |
---|---|
dest |
Parcel : The Parcel in which the object should be written.
This value cannot be null . |
flags |
int : Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE .
Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE , and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.