PlaybackStateCompat
public final class PlaybackStateCompat implements Parcelable
Playback state for a MediaSessionCompat. This includes a state like STATE_PLAYING, the current playback position, and the current control capabilities.
Summary
Nested types |
|---|
public final class PlaybackStateCompat.BuilderBuilder for |
public final class PlaybackStateCompat.CustomAction implements Parcelable
|
public final class PlaybackStateCompat.CustomAction.BuilderBuilder for |
Constants |
|
|---|---|
static final long |
ACTION_FAST_FORWARD = 64Indicates this session supports the fast forward command. |
static final long |
ACTION_PAUSE = 2Indicates this session supports the pause command. |
static final long |
ACTION_PLAY = 4Indicates this session supports the play command. |
static final long |
ACTION_PLAY_FROM_MEDIA_ID = 1024Indicates this session supports the play from media id command. |
static final long |
ACTION_PLAY_FROM_SEARCH = 2048Indicates this session supports the play from search command. |
static final long |
ACTION_PLAY_FROM_URI = 8192Indicates this session supports the play from URI command. |
static final long |
ACTION_PLAY_PAUSE = 512Indicates this session supports the play/pause toggle command. |
static final long |
ACTION_PREPARE = 16384Indicates this session supports the prepare command. |
static final long |
ACTION_PREPARE_FROM_MEDIA_ID = 32768Indicates this session supports the prepare from media id command. |
static final long |
ACTION_PREPARE_FROM_SEARCH = 65536Indicates this session supports the prepare from search command. |
static final long |
ACTION_PREPARE_FROM_URI = 131072Indicates this session supports the prepare from URI command. |
static final long |
ACTION_REWIND = 8Indicates this session supports the rewind command. |
static final long |
ACTION_SEEK_TO = 256Indicates this session supports the seek to command. |
static final long |
ACTION_SET_CAPTIONING_ENABLED = 1048576Indicates this session supports the set captioning enabled command. |
static final long |
ACTION_SET_PLAYBACK_SPEED = 4194304Indicates this session supports the set playback speed command. |
static final long |
ACTION_SET_RATING = 128Indicates this session supports the set rating command. |
static final long |
ACTION_SET_REPEAT_MODE = 262144Indicates this session supports the set repeat mode command. |
static final long |
ACTION_SET_SHUFFLE_MODE = 2097152Indicates this session supports the set shuffle mode command. |
static final long |
ACTION_SET_SHUFFLE_MODE_ENABLED = 524288This field is deprecated. Use |
static final long |
ACTION_SKIP_TO_NEXT = 32Indicates this session supports the next command. |
static final long |
Indicates this session supports the previous command. |
static final long |
ACTION_SKIP_TO_QUEUE_ITEM = 4096Indicates this session supports the skip to queue item command. |
static final long |
ACTION_STOP = 1Indicates this session supports the stop command. |
static final Parcelable.Creator<PlaybackStateCompat> |
|
static final int |
Error code when the action is interrupted due to some external event. |
static final int |
Error code when the application state is invalid to fulfill the request. |
static final int |
Error code when the request cannot be performed because authentication has expired. |
static final int |
Error code when too many concurrent streams are detected. |
static final int |
Error code when the requested content is already playing. |
static final int |
Error code when the playback navigation (previous, next) is not possible because the queue was exhausted. |
static final int |
Error code when the content is blocked due to being regionally unavailable. |
static final int |
Error code when the request is not supported by the application. |
static final int |
Error code when the content is blocked due to parental controls. |
static final int |
Error code when a premium account is required for the request to succeed. |
static final int |
Error code when the application cannot skip any more songs because skip limit is reached. |
static final int |
This is the default error code and indicates that none of the other error codes applies. |
static final long |
Use this value for the position to indicate the position is not known. |
static final int |
REPEAT_MODE_ALL = 2Use this value with |
static final int |
Use this value with |
static final int |
REPEAT_MODE_INVALID = -1
|
static final int |
REPEAT_MODE_NONE = 0Use this value with |
static final int |
REPEAT_MODE_ONE = 1Use this value with |
static final int |
SHUFFLE_MODE_ALL = 1Use this value with |
static final int |
Use this value with |
static final int |
SHUFFLE_MODE_INVALID = -1
|
static final int |
Use this value with |
static final int |
STATE_BUFFERING = 6State indicating this item is currently buffering and will begin playing when enough data has buffered. |
static final int |
STATE_CONNECTING = 8State indicating the class doing playback is currently connecting to a route. |
static final int |
STATE_ERROR = 7State indicating this item is currently in an error state. |
static final int |
State indicating this item is currently fast forwarding. |
static final int |
STATE_NONE = 0This 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 final int |
STATE_PAUSED = 2State indicating this item is currently paused. |
static final int |
STATE_PLAYING = 3State indicating this item is currently playing. |
static final int |
STATE_REWINDING = 5State indicating this item is currently rewinding. |
static final int |
State indicating the player is currently skipping to the next item. |
static final int |
State indicating the player is currently skipping to the previous item. |
static final int |
State indicating the player is currently skipping to a specific item in the queue. |
static final int |
STATE_STOPPED = 1State indicating this item is currently stopped. |
Public methods |
|
|---|---|
int |
|
static PlaybackStateCompat |
fromPlaybackState(Object stateObj)Creates an instance from a framework |
long |
Get the current actions available on this session. |
long |
Get the id of the currently active item in the queue. |
long |
Get the current buffered position in ms. |
List<PlaybackStateCompat.CustomAction> |
Get the list of custom actions. |
int |
Get the error code. |
CharSequence |
Get the user readable optional error message. |
@Nullable Bundle |
Get any custom extras that were set on this playback state. |
long |
Get the elapsed real time at which position was last updated. |
float |
Get the current playback speed as a multiple of normal playback. |
Object |
Gets the underlying framework |
long |
Get the playback position in ms at last position update time. |
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 Constants |
||||
|---|---|---|---|---|
|
Constants
ACTION_FAST_FORWARD
public static final long ACTION_FAST_FORWARD = 64
Indicates this session supports the fast forward command.
| See also | |
|---|---|
setActions |
ACTION_PAUSE
public static final long ACTION_PAUSE = 2
Indicates this session supports the pause command.
| See also | |
|---|---|
setActions |
ACTION_PLAY
public static final long ACTION_PLAY = 4
Indicates this session supports the play command.
| See also | |
|---|---|
setActions |
ACTION_PLAY_FROM_MEDIA_ID
public static final long ACTION_PLAY_FROM_MEDIA_ID = 1024
Indicates this session supports the play from media id command.
| See also | |
|---|---|
setActions |
ACTION_PLAY_FROM_SEARCH
public static final long ACTION_PLAY_FROM_SEARCH = 2048
Indicates this session supports the play from search command.
| See also | |
|---|---|
setActions |
ACTION_PLAY_FROM_URI
public static final long ACTION_PLAY_FROM_URI = 8192
Indicates this session supports the play from URI command.
| See also | |
|---|---|
setActions |
ACTION_PLAY_PAUSE
public static final long ACTION_PLAY_PAUSE = 512
Indicates this session supports the play/pause toggle command.
| See also | |
|---|---|
setActions |
ACTION_PREPARE
public static final long ACTION_PREPARE = 16384
Indicates this session supports the prepare command.
| See also | |
|---|---|
setActions |
ACTION_PREPARE_FROM_MEDIA_ID
public static final long ACTION_PREPARE_FROM_MEDIA_ID = 32768
Indicates this session supports the prepare from media id command.
| See also | |
|---|---|
setActions |
ACTION_PREPARE_FROM_SEARCH
public static final long ACTION_PREPARE_FROM_SEARCH = 65536
Indicates this session supports the prepare from search command.
| See also | |
|---|---|
setActions |
ACTION_PREPARE_FROM_URI
public static final long ACTION_PREPARE_FROM_URI = 131072
Indicates this session supports the prepare from URI command.
| See also | |
|---|---|
setActions |
ACTION_REWIND
public static final long ACTION_REWIND = 8
Indicates this session supports the rewind command.
| See also | |
|---|---|
setActions |
ACTION_SEEK_TO
public static final long ACTION_SEEK_TO = 256
Indicates this session supports the seek to command.
| See also | |
|---|---|
setActions |
ACTION_SET_CAPTIONING_ENABLED
public static final long ACTION_SET_CAPTIONING_ENABLED = 1048576
Indicates this session supports the set captioning enabled command.
| See also | |
|---|---|
setActions |
ACTION_SET_PLAYBACK_SPEED
public static final long ACTION_SET_PLAYBACK_SPEED = 4194304
Indicates this session supports the set playback speed command.
| See also | |
|---|---|
setActions |
ACTION_SET_RATING
public static final long ACTION_SET_RATING = 128
Indicates this session supports the set rating command.
| See also | |
|---|---|
setActions |
ACTION_SET_REPEAT_MODE
public static final long ACTION_SET_REPEAT_MODE = 262144
Indicates this session supports the set repeat mode command.
| See also | |
|---|---|
setActions |
ACTION_SET_SHUFFLE_MODE
public static final long ACTION_SET_SHUFFLE_MODE = 2097152
Indicates this session supports the set shuffle mode command.
| See also | |
|---|---|
setActions |
public static final long ACTION_SET_SHUFFLE_MODE_ENABLED = 524288
Indicates this session supports the set shuffle mode enabled command.
| See also | |
|---|---|
setActions |
ACTION_SKIP_TO_NEXT
public static final long ACTION_SKIP_TO_NEXT = 32
Indicates this session supports the next command.
| See also | |
|---|---|
setActions |
ACTION_SKIP_TO_PREVIOUS
public static final long ACTION_SKIP_TO_PREVIOUS = 16
Indicates this session supports the previous command.
| See also | |
|---|---|
setActions |
ACTION_SKIP_TO_QUEUE_ITEM
public static final long ACTION_SKIP_TO_QUEUE_ITEM = 4096
Indicates this session supports the skip to queue item command.
| See also | |
|---|---|
setActions |
ACTION_STOP
public static final long ACTION_STOP = 1
Indicates this session supports the stop command.
| See also | |
|---|---|
setActions |
ERROR_CODE_ACTION_ABORTED
public static final int ERROR_CODE_ACTION_ABORTED = 10
Error code when the action is interrupted due to some external event. The error code should be set when entering STATE_ERROR.
ERROR_CODE_APP_ERROR
public static final int ERROR_CODE_APP_ERROR = 1
Error code when the application state is invalid to fulfill the request. The error code should be set when entering STATE_ERROR.
ERROR_CODE_AUTHENTICATION_EXPIRED
public static final int ERROR_CODE_AUTHENTICATION_EXPIRED = 3
Error code when the request cannot be performed because authentication has expired. The error code should be set when entering STATE_ERROR.
ERROR_CODE_CONCURRENT_STREAM_LIMIT
public static final int ERROR_CODE_CONCURRENT_STREAM_LIMIT = 5
Error code when too many concurrent streams are detected. The error code should be set when entering STATE_ERROR.
ERROR_CODE_CONTENT_ALREADY_PLAYING
public static final int ERROR_CODE_CONTENT_ALREADY_PLAYING = 8
Error code when the requested content is already playing. The error code should be set when entering STATE_ERROR.
ERROR_CODE_END_OF_QUEUE
public static final int ERROR_CODE_END_OF_QUEUE = 11
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.
ERROR_CODE_NOT_AVAILABLE_IN_REGION
public static final int ERROR_CODE_NOT_AVAILABLE_IN_REGION = 7
Error code when the content is blocked due to being regionally unavailable. The error code should be set when entering STATE_ERROR.
ERROR_CODE_NOT_SUPPORTED
public static final int ERROR_CODE_NOT_SUPPORTED = 2
Error code when the request is not supported by the application. The error code should be set when entering STATE_ERROR.
ERROR_CODE_PARENTAL_CONTROL_RESTRICTED
public static final int ERROR_CODE_PARENTAL_CONTROL_RESTRICTED = 6
Error code when the content is blocked due to parental controls. The error code should be set when entering STATE_ERROR.
ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED
public static final int ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED = 4
Error code when a premium account is required for the request to succeed. The error code should be set when entering STATE_ERROR.
ERROR_CODE_SKIP_LIMIT_REACHED
public static final int ERROR_CODE_SKIP_LIMIT_REACHED = 9
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.
ERROR_CODE_UNKNOWN_ERROR
public static final int ERROR_CODE_UNKNOWN_ERROR = 0
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.
PLAYBACK_POSITION_UNKNOWN
public static final long PLAYBACK_POSITION_UNKNOWN = -1
Use this value for the position to indicate the position is not known.
REPEAT_MODE_ALL
public static final int REPEAT_MODE_ALL = 2
Use this value with setRepeatMode to indicate that the playback of the playing media list will be repeated.
REPEAT_MODE_GROUP
public static final int REPEAT_MODE_GROUP = 3
Use this value with setRepeatMode 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.
REPEAT_MODE_INVALID
public static final int REPEAT_MODE_INVALID = -1
getRepeatMode returns this value when the session is not ready for providing its repeat mode.
REPEAT_MODE_NONE
public static final int REPEAT_MODE_NONE = 0
Use this value with setRepeatMode to indicate that the playback will be stopped at the end of the playing media list.
REPEAT_MODE_ONE
public static final int REPEAT_MODE_ONE = 1
Use this value with setRepeatMode to indicate that the playback of the current playing media item will be repeated.
SHUFFLE_MODE_ALL
public static final int SHUFFLE_MODE_ALL = 1
Use this value with setShuffleMode to indicate that the media list will be played in shuffled order.
SHUFFLE_MODE_GROUP
public static final int SHUFFLE_MODE_GROUP = 2
Use this value with setShuffleMode 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.
SHUFFLE_MODE_INVALID
public static final int SHUFFLE_MODE_INVALID = -1
getShuffleMode returns this value when the session is not ready for providing its shuffle mode.
SHUFFLE_MODE_NONE
public static final int SHUFFLE_MODE_NONE = 0
Use this value with setShuffleMode to indicate that the media list will be played in order.
STATE_BUFFERING
public static final int STATE_BUFFERING = 6
State indicating this item is currently buffering and will begin playing when enough data has buffered.
| See also | |
|---|---|
PlaybackStateCompat.Builder |
STATE_CONNECTING
public static final int STATE_CONNECTING = 8
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 | |
|---|---|
PlaybackStateCompat.Builder |
STATE_ERROR
public static final int STATE_ERROR = 7
State indicating this item is currently in an error state. The error code should also be set when entering this state.
STATE_FAST_FORWARDING
public static final int STATE_FAST_FORWARDING = 4
State indicating this item is currently fast forwarding.
| See also | |
|---|---|
PlaybackStateCompat.Builder |
STATE_NONE
public static final int STATE_NONE = 0
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 | |
|---|---|
PlaybackStateCompat.Builder |
STATE_PAUSED
public static final int STATE_PAUSED = 2
State indicating this item is currently paused.
| See also | |
|---|---|
PlaybackStateCompat.Builder |
STATE_PLAYING
public static final int STATE_PLAYING = 3
State indicating this item is currently playing.
| See also | |
|---|---|
PlaybackStateCompat.Builder |
STATE_REWINDING
public static final int STATE_REWINDING = 5
State indicating this item is currently rewinding.
| See also | |
|---|---|
PlaybackStateCompat.Builder |
STATE_SKIPPING_TO_NEXT
public static final int STATE_SKIPPING_TO_NEXT = 10
State indicating the player is currently skipping to the next item.
| See also | |
|---|---|
PlaybackStateCompat.Builder |
STATE_SKIPPING_TO_PREVIOUS
public static final int STATE_SKIPPING_TO_PREVIOUS = 9
State indicating the player is currently skipping to the previous item.
| See also | |
|---|---|
PlaybackStateCompat.Builder |
STATE_SKIPPING_TO_QUEUE_ITEM
public static final int STATE_SKIPPING_TO_QUEUE_ITEM = 11
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 | |
|---|---|
PlaybackStateCompat.Builder |
STATE_STOPPED
public static final int STATE_STOPPED = 1
State indicating this item is currently stopped.
| See also | |
|---|---|
PlaybackStateCompat.Builder |
Public methods
fromPlaybackState
public static PlaybackStateCompat fromPlaybackState(Object stateObj)
Creates an instance from a framework android.media.session.PlaybackState object.
This method is only supported on API 21+.
| Parameters | |
|---|---|
Object stateObj |
A |
| Returns | |
|---|---|
PlaybackStateCompat |
An equivalent |
getActions
public 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_ENABLEDACTION_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 UNKNOWN_ID.
| Returns | |
|---|---|
long |
The id of the currently active item in the queue or |
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.
getCustomActions
public List<PlaybackStateCompat.CustomAction> getCustomActions()
Get the list of custom actions.
getErrorCode
public int getErrorCode()
Get the error code. This should be set when the state is STATE_ERROR.
getErrorMessage
public CharSequence getErrorMessage()
Get the user readable optional error message. This may be set when the state is STATE_ERROR.
| See also | |
|---|---|
getErrorCode |
getExtras
public @Nullable Bundle getExtras()
Get any custom extras that were set on this playback state.
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. |
getPlaybackState
public Object getPlaybackState()
Gets the underlying framework android.media.session.PlaybackState object.
This method is only supported on API 21+.
| Returns | |
|---|---|
Object |
An equivalent |
getPosition
public long getPosition()
Get the playback position in ms at last position update time.
getState
public int getState()
Get the current state of playback. One of the following:
toKeyCode
public static 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 | |
|---|---|
long action |
The action to be translated. |
| Returns | |
|---|---|
int |
the key code matched to the given action. |