public
final
class
PlaybackStateCompat
extends Object
implements
Parcelable
| java.lang.Object | |
| ↳ | android.support.v4.media.session.PlaybackStateCompat |
Playback state for a MediaSessionCompat. This includes a state like
STATE_PLAYING, the current playback position,
and the current control capabilities.
classPlaybackStateCompat.Builder
Builder for PlaybackStateCompat objects.
classPlaybackStateCompat.CustomAction
CustomActions can be used to
extend the capabilities of the standard transport controls by exposing
app specific actions to Controllers.
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_CAPTIONING_ENABLED
Indicates this session supports the set captioning enabled command. |
long |
ACTION_SET_RATING
Indicates this session supports the set rating command. |
long |
ACTION_SET_REPEAT_MODE
Indicates this session supports the set repeat mode command. |
long |
ACTION_SET_SHUFFLE_MODE
Indicates this session supports the set shuffle mode command. |
long |
ACTION_SET_SHUFFLE_MODE_ENABLED
This constant was deprecated
in API level 27.1.0.
Use |
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. |
int |
ERROR_CODE_ACTION_ABORTED
Error code when the action is interrupted due to some external event. |
int |
ERROR_CODE_APP_ERROR
Error code when the application state is invalid to fulfill the request. |
int |
ERROR_CODE_AUTHENTICATION_EXPIRED
Error code when the request cannot be performed because authentication has expired. |
int |
ERROR_CODE_CONCURRENT_STREAM_LIMIT
Error code when too many concurrent streams are detected. |
int |
ERROR_CODE_CONTENT_ALREADY_PLAYING
Error code when the requested content is already playing. |
int |
ERROR_CODE_END_OF_QUEUE
Error code when the playback navigation (previous, next) is not possible because the queue was exhausted. |
int |
ERROR_CODE_NOT_AVAILABLE_IN_REGION
Error code when the content is blocked due to being regionally unavailable. |
int |
ERROR_CODE_NOT_SUPPORTED
Error code when the request is not supported by the application. |
int |
ERROR_CODE_PARENTAL_CONTROL_RESTRICTED
Error code when the content is blocked due to parental controls. |
int |
ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED
Error code when a premium account is required for the request to succeed. |
int |
ERROR_CODE_SKIP_LIMIT_REACHED
Error code when the application cannot skip any more songs because skip limit is reached. |
int |
ERROR_CODE_UNKNOWN_ERROR
This is the default error code and indicates that none of the other error codes applies. |
long |
PLAYBACK_POSITION_UNKNOWN
Use this value for the position to indicate the position is not known. |
int |
REPEAT_MODE_ALL
Use this value with |
int |
REPEAT_MODE_GROUP
Use this value with |
int |
REPEAT_MODE_INVALID
|
int |
REPEAT_MODE_NONE
Use this value with |
int |
REPEAT_MODE_ONE
Use this value with |
int |
SHUFFLE_MODE_ALL
Use this value with |
int |
SHUFFLE_MODE_GROUP
Use this value with |
int |
SHUFFLE_MODE_INVALID
|
int |
SHUFFLE_MODE_NONE
Use this value with |
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 route. |
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 |
|---|
android.os.Parcelable
|
Fields | |
|---|---|
public
static
final
Creator<PlaybackStateCompat> |
CREATOR
|
Public methods | |
|---|---|
int
|
describeContents()
|
static
PlaybackStateCompat
|
fromPlaybackState(Object stateObj)
Creates an instance from a framework |
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. |
int
|
getErrorCode()
Get the error code. |
CharSequence
|
getErrorMessage()
Get the user readable optional 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 |
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 |
String
|
toString()
|
void
|
writeToParcel(Parcel dest, int flags)
|
Inherited methods | |
|---|---|
java.lang.Object
| |
android.os.Parcelable
| |
long ACTION_FAST_FORWARD
Indicates this session supports the fast forward command.
See also:
Constant Value: 64 (0x0000000000000040)
long ACTION_PAUSE
Indicates this session supports the pause command.
See also:
Constant Value: 2 (0x0000000000000002)
long ACTION_PLAY
Indicates this session supports the play command.
See also:
Constant Value: 4 (0x0000000000000004)
long ACTION_PLAY_FROM_MEDIA_ID
Indicates this session supports the play from media id command.
See also:
Constant Value: 1024 (0x0000000000000400)
long ACTION_PLAY_FROM_SEARCH
Indicates this session supports the play from search command.
See also:
Constant Value: 2048 (0x0000000000000800)
long ACTION_PLAY_FROM_URI
Indicates this session supports the play from URI command.
See also:
Constant Value: 8192 (0x0000000000002000)
long ACTION_PLAY_PAUSE
Indicates this session supports the play/pause toggle command.
See also:
Constant Value: 512 (0x0000000000000200)
long ACTION_PREPARE
Indicates this session supports the prepare command.
See also:
Constant Value: 16384 (0x0000000000004000)
long ACTION_PREPARE_FROM_MEDIA_ID
Indicates this session supports the prepare from media id command.
See also:
Constant Value: 32768 (0x0000000000008000)
long ACTION_PREPARE_FROM_SEARCH
Indicates this session supports the prepare from search command.
See also:
Constant Value: 65536 (0x0000000000010000)
long ACTION_PREPARE_FROM_URI
Indicates this session supports the prepare from URI command.
See also:
Constant Value: 131072 (0x0000000000020000)
long ACTION_REWIND
Indicates this session supports the rewind command.
See also:
Constant Value: 8 (0x0000000000000008)
long ACTION_SEEK_TO
Indicates this session supports the seek to command.
See also:
Constant Value: 256 (0x0000000000000100)
long ACTION_SET_CAPTIONING_ENABLED
Indicates this session supports the set captioning enabled command.
See also:
Constant Value: 1048576 (0x0000000000100000)
long ACTION_SET_RATING
Indicates this session supports the set rating command.
See also:
Constant Value: 128 (0x0000000000000080)
long ACTION_SET_REPEAT_MODE
Indicates this session supports the set repeat mode command.
See also:
Constant Value: 262144 (0x0000000000040000)
long ACTION_SET_SHUFFLE_MODE
Indicates this session supports the set shuffle mode command.
See also:
Constant Value: 2097152 (0x0000000000200000)
long ACTION_SET_SHUFFLE_MODE_ENABLED
This constant was deprecated
in API level 27.1.0.
Use ACTION_SET_SHUFFLE_MODE instead.
Indicates this session supports the set shuffle mode enabled command.
See also:
Constant Value: 524288 (0x0000000000080000)
long ACTION_SKIP_TO_NEXT
Indicates this session supports the next command.
See also:
Constant Value: 32 (0x0000000000000020)
long ACTION_SKIP_TO_PREVIOUS
Indicates this session supports the previous command.
See also:
Constant Value: 16 (0x0000000000000010)
long ACTION_SKIP_TO_QUEUE_ITEM
Indicates this session supports the skip to queue item command.
See also:
Constant Value: 4096 (0x0000000000001000)
long ACTION_STOP
Indicates this session supports the stop command.
See also:
Constant Value: 1 (0x0000000000000001)
int ERROR_CODE_ACTION_ABORTED
Error code when the action is interrupted due to some external event.
The error code should be set when entering STATE_ERROR.
Constant Value: 10 (0x0000000a)
int ERROR_CODE_APP_ERROR
Error code when the application state is invalid to fulfill the request.
The error code should be set when entering STATE_ERROR.
Constant Value: 1 (0x00000001)
int ERROR_CODE_AUTHENTICATION_EXPIRED
Error code when the request cannot be performed because authentication has expired.
The error code should be set when entering STATE_ERROR.
Constant Value: 3 (0x00000003)
int ERROR_CODE_CONCURRENT_STREAM_LIMIT
Error code when too many concurrent streams are detected.
The error code should be set when entering STATE_ERROR.
Constant Value: 5 (0x00000005)
int ERROR_CODE_CONTENT_ALREADY_PLAYING
Error code when the requested content is already playing.
The error code should be set when entering STATE_ERROR.
Constant Value: 8 (0x00000008)
int ERROR_CODE_END_OF_QUEUE
Error code when the playback navigation (previous, next) is not possible because the queue
was exhausted.
The error code should be set when entering STATE_ERROR.
Constant Value: 11 (0x0000000b)
int ERROR_CODE_NOT_AVAILABLE_IN_REGION
Error code when the content is blocked due to being regionally unavailable.
The error code should be set when entering STATE_ERROR.
Constant Value: 7 (0x00000007)
int ERROR_CODE_NOT_SUPPORTED
Error code when the request is not supported by the application.
The error code should be set when entering STATE_ERROR.
Constant Value: 2 (0x00000002)
int ERROR_CODE_PARENTAL_CONTROL_RESTRICTED
Error code when the content is blocked due to parental controls.
The error code should be set when entering STATE_ERROR.
Constant Value: 6 (0x00000006)
int ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED
Error code when a premium account is required for the request to succeed.
The error code should be set when entering STATE_ERROR.
Constant Value: 4 (0x00000004)
int ERROR_CODE_SKIP_LIMIT_REACHED
Error code when the application cannot skip any more songs because skip limit is reached.
The error code should be set when entering STATE_ERROR.
Constant Value: 9 (0x00000009)
int ERROR_CODE_UNKNOWN_ERROR
This is the default error code and indicates that none of the other error codes applies.
The error code should be set when entering STATE_ERROR.
Constant Value: 0 (0x00000000)
long PLAYBACK_POSITION_UNKNOWN
Use this value for the position to indicate the position is not known.
Constant Value: -1 (0xffffffffffffffff)
int REPEAT_MODE_ALL
Use this value with setRepeatMode(int)
to indicate that the playback of the playing media list will be repeated.
Constant Value: 2 (0x00000002)
int REPEAT_MODE_GROUP
Use this value with setRepeatMode(int)
to indicate that the playback of the playing media group will be repeated.
A group is a logical block of media items which is specified in the section 5.7 of the
Bluetooth AVRCP 1.6.
Constant Value: 3 (0x00000003)
int REPEAT_MODE_INVALID
getRepeatMode() returns this value
when the session is not ready for providing its repeat mode.
Constant Value: -1 (0xffffffff)
int REPEAT_MODE_NONE
Use this value with setRepeatMode(int)
to indicate that the playback will be stopped at the end of the playing media list.
Constant Value: 0 (0x00000000)
int REPEAT_MODE_ONE
Use this value with setRepeatMode(int)
to indicate that the playback of the current playing media item will be repeated.
Constant Value: 1 (0x00000001)
int SHUFFLE_MODE_ALL
Use this value with setShuffleMode(int)
to indicate that the media list will be played in shuffled order.
Constant Value: 1 (0x00000001)
int SHUFFLE_MODE_GROUP
Use this value with setShuffleMode(int)
to indicate that the media group will be played in shuffled order.
A group is a logical block of media items which is specified in the section 5.7 of the
Bluetooth AVRCP 1.6.
Constant Value: 2 (0x00000002)
int SHUFFLE_MODE_INVALID
getShuffleMode() returns this value
when the session is not ready for providing its shuffle mode.
Constant Value: -1 (0xffffffff)
int SHUFFLE_MODE_NONE
Use this value with setShuffleMode(int)
to indicate that the media list will be played in order.
Constant Value: 0 (0x00000000)
int STATE_BUFFERING
State indicating this item is currently buffering and will begin playing when enough data has buffered.
See also:
Constant Value: 6 (0x00000006)
int STATE_CONNECTING
State indicating the class doing playback is currently connecting to a
route. 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.
On devices earlier than API 21, this will appear as STATE_BUFFERING
See also:
Constant Value: 8 (0x00000008)
int STATE_ERROR
State indicating this item is currently in an error state. The error code should also be set when entering this state.
Constant Value: 7 (0x00000007)
int STATE_FAST_FORWARDING
State indicating this item is currently fast forwarding.
See also:
Constant Value: 4 (0x00000004)
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)
int STATE_PAUSED
State indicating this item is currently paused.
See also:
Constant Value: 2 (0x00000002)
int STATE_PLAYING
State indicating this item is currently playing.
See also:
Constant Value: 3 (0x00000003)
int STATE_REWINDING
State indicating this item is currently rewinding.
See also:
Constant Value: 5 (0x00000005)
int STATE_SKIPPING_TO_NEXT
State indicating the player is currently skipping to the next item.
See also:
Constant Value: 10 (0x0000000a)
int STATE_SKIPPING_TO_PREVIOUS
State indicating the player is currently skipping to the previous item.
See also:
Constant Value: 9 (0x00000009)
int STATE_SKIPPING_TO_QUEUE_ITEM
State indicating the player is currently skipping to a specific item in the queue.
On devices earlier than API 21, this will appear as STATE_SKIPPING_TO_NEXT
See also:
Constant Value: 11 (0x0000000b)
int STATE_STOPPED
State indicating this item is currently stopped.
See also:
Constant Value: 1 (0x00000001)
PlaybackStateCompat fromPlaybackState (Object stateObj)
Creates an instance from a framework PlaybackState object.
This method is only supported on API 21+.
| Parameters | |
|---|---|
stateObj |
Object: A PlaybackState object, or null if none. |
| Returns | |
|---|---|
PlaybackStateCompat |
An equivalent PlaybackStateCompat object, or null if none.
|
long getActions ()
Get the current actions available on this session. This should use a bitmask of the available actions.
ACTION_SKIP_TO_PREVIOUSACTION_REWINDACTION_PLAYACTION_PLAY_PAUSEACTION_PAUSEACTION_STOPACTION_FAST_FORWARDACTION_SKIP_TO_NEXTACTION_SEEK_TOACTION_SET_RATINGACTION_PLAY_FROM_MEDIA_IDACTION_PLAY_FROM_SEARCHACTION_SKIP_TO_QUEUE_ITEMACTION_PLAY_FROM_URIACTION_PREPAREACTION_PREPARE_FROM_MEDIA_IDACTION_PREPARE_FROM_SEARCHACTION_PREPARE_FROM_URIACTION_SET_REPEAT_MODEACTION_SET_SHUFFLE_MODEACTION_SET_CAPTIONING_ENABLED| Returns | |
|---|---|
long |
|
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
UNKNOWN_ID.
| Returns | |
|---|---|
long |
The id of the currently active item in the queue or
UNKNOWN_ID.
|
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 |
|
List<PlaybackStateCompat.CustomAction> getCustomActions ()
Get the list of custom actions.
| Returns | |
|---|---|
List<PlaybackStateCompat.CustomAction> |
|
int getErrorCode ()
Get the error code. This should be set when the state is
STATE_ERROR.
| Returns | |
|---|---|
int |
|
See also:
ERROR_CODE_UNKNOWN_ERRORERROR_CODE_APP_ERRORERROR_CODE_NOT_SUPPORTEDERROR_CODE_AUTHENTICATION_EXPIREDERROR_CODE_PREMIUM_ACCOUNT_REQUIREDERROR_CODE_CONCURRENT_STREAM_LIMITERROR_CODE_PARENTAL_CONTROL_RESTRICTEDERROR_CODE_NOT_AVAILABLE_IN_REGIONERROR_CODE_CONTENT_ALREADY_PLAYINGERROR_CODE_SKIP_LIMIT_REACHEDERROR_CODE_ACTION_ABORTEDERROR_CODE_END_OF_QUEUEgetErrorMessage()CharSequence getErrorMessage ()
Get the user readable optional error message. This may be set when the state is
STATE_ERROR.
| Returns | |
|---|---|
CharSequence |
|
See also:
Bundle getExtras ()
Get any custom extras that were set on this playback state.
| Returns | |
|---|---|
Bundle |
The extras for this state or null. |
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. |
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. |
Object getPlaybackState ()
Gets the underlying framework PlaybackState object.
This method is only supported on API 21+.
| Returns | |
|---|---|
Object |
An equivalent PlaybackState object, or null if none.
|
long getPosition ()
Get the current playback position in ms.
| Returns | |
|---|---|
long |
|
int getState ()
STATE_NONESTATE_STOPPEDSTATE_PLAYINGSTATE_PAUSEDSTATE_FAST_FORWARDINGSTATE_REWINDINGSTATE_BUFFERINGSTATE_ERRORSTATE_CONNECTINGSTATE_SKIPPING_TO_PREVIOUSSTATE_SKIPPING_TO_NEXTSTATE_SKIPPING_TO_QUEUE_ITEM| Returns | |
|---|---|
int |
|
int toKeyCode (long action)
Translates a given action into a matched key code defined in KeyEvent. The given
action should be one of the following:
ACTION_PLAYACTION_PAUSEACTION_SKIP_TO_NEXTACTION_SKIP_TO_PREVIOUSACTION_STOPACTION_FAST_FORWARDACTION_REWINDACTION_PLAY_PAUSE| Parameters | |
|---|---|
action |
long: The action to be translated. |
| Returns | |
|---|---|
int |
the key code matched to the given action. |
String toString ()
| Returns | |
|---|---|
String |
|
void writeToParcel (Parcel dest, int flags)
| Parameters | |
|---|---|
dest |
Parcel |
flags |
int |
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 2025-02-10 UTC.