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.Builder

Builder for PlaybackStateCompat objects.

public final class PlaybackStateCompat.CustomAction implements Parcelable

CustomActions can be used to extend the capabilities of the standard transport controls by exposing app specific actions to Controllers.

Builder for CustomAction objects.

Constants

static final long

Indicates this session supports the fast forward command.

static final long

Indicates this session supports the pause command.

static final long

Indicates this session supports the play command.

static final long

Indicates this session supports the play from media id command.

static final long

Indicates this session supports the play from search command.

static final long

Indicates this session supports the play from URI command.

static final long

Indicates this session supports the play/pause toggle command.

static final long

Indicates this session supports the prepare command.

static final long

Indicates this session supports the prepare from media id command.

static final long

Indicates this session supports the prepare from search command.

static final long

Indicates this session supports the prepare from URI command.

static final long

Indicates this session supports the rewind command.

static final long

Indicates this session supports the seek to command.

static final long

Indicates this session supports the set captioning enabled command.

static final long

Indicates this session supports the set playback speed command.

static final long

Indicates this session supports the set rating command.

static final long

Indicates this session supports the set repeat mode command.

static final long

Indicates this session supports the set shuffle mode command.

static final long

This field is deprecated.

Use ACTION_SET_SHUFFLE_MODE instead.

static final long

Indicates this session supports the next command.

static final long

Indicates this session supports the previous command.

static final long

Indicates this session supports the skip to queue item command.

static final long

Indicates 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

Use this value with setRepeatMode to indicate that the playback of the playing media list will be repeated.

static final int

Use this value with setRepeatMode to indicate that the playback of the playing media group will be repeated.

static final int

getRepeatMode returns this value when the session is not ready for providing its repeat mode.

static final int

Use this value with setRepeatMode to indicate that the playback will be stopped at the end of the playing media list.

static final int

Use this value with setRepeatMode to indicate that the playback of the current playing media item will be repeated.

static final int

Use this value with setShuffleMode to indicate that the media list will be played in shuffled order.

static final int

Use this value with setShuffleMode to indicate that the media group will be played in shuffled order.

static final int

getShuffleMode returns this value when the session is not ready for providing its shuffle mode.

static final int

Use this value with setShuffleMode to indicate that the media list will be played in order.

static final int

State indicating this item is currently buffering and will begin playing when enough data has buffered.

static final int

State indicating the class doing playback is currently connecting to a route.

static final int

State indicating this item is currently in an error state.

static final int

State indicating this item is currently fast forwarding.

static final int

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 final int

State indicating this item is currently paused.

static final int

State indicating this item is currently playing.

static final int

State 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 indicating this item is currently stopped.

Public methods

int
static PlaybackStateCompat

Creates an instance from a framework android.media.session.PlaybackState object.

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 android.media.session.PlaybackState object.

long

Get the playback position in ms at last position update time.

int

Get the current state of playback.

static int
toKeyCode(long action)

Translates a given action into a matched key code defined in KeyEvent.

String
void
writeToParcel(Parcel dest, int flags)

Inherited Constants

From android.os.Parcelable
static final int
static final int

Constants

ACTION_FAST_FORWARD

Added in 1.1.0
public static final long ACTION_FAST_FORWARD = 64

Indicates this session supports the fast forward command.

See also
setActions

ACTION_PAUSE

Added in 1.1.0
public static final long ACTION_PAUSE = 2

Indicates this session supports the pause command.

See also
setActions

ACTION_PLAY

Added in 1.1.0
public static final long ACTION_PLAY = 4

Indicates this session supports the play command.

See also
setActions

ACTION_PLAY_FROM_MEDIA_ID

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
public static final long ACTION_PLAY_FROM_URI = 8192

Indicates this session supports the play from URI command.

See also
setActions

ACTION_PLAY_PAUSE

Added in 1.1.0
public static final long ACTION_PLAY_PAUSE = 512

Indicates this session supports the play/pause toggle command.

See also
setActions

ACTION_PREPARE

Added in 1.1.0
public static final long ACTION_PREPARE = 16384

Indicates this session supports the prepare command.

See also
setActions

ACTION_PREPARE_FROM_MEDIA_ID

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
public static final long ACTION_PREPARE_FROM_URI = 131072

Indicates this session supports the prepare from URI command.

See also
setActions

ACTION_REWIND

Added in 1.1.0
public static final long ACTION_REWIND = 8

Indicates this session supports the rewind command.

See also
setActions

ACTION_SEEK_TO

Added in 1.1.0
public static final long ACTION_SEEK_TO = 256

Indicates this session supports the seek to command.

See also
setActions

ACTION_SET_CAPTIONING_ENABLED

Added in 1.1.0
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

Added in 1.3.0
public static final long ACTION_SET_PLAYBACK_SPEED = 4194304

Indicates this session supports the set playback speed command.

See also
setActions

ACTION_SET_RATING

Added in 1.1.0
public static final long ACTION_SET_RATING = 128

Indicates this session supports the set rating command.

See also
setActions

ACTION_SET_REPEAT_MODE

Added in 1.1.0
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

Added in 1.1.0
public static final long ACTION_SET_SHUFFLE_MODE = 2097152

Indicates this session supports the set shuffle mode command.

See also
setActions

ACTION_SET_SHUFFLE_MODE_ENABLED

Added in 1.1.0
Deprecated in 1.1.0
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

Added in 1.1.0
public static final long ACTION_SKIP_TO_NEXT = 32

Indicates this session supports the next command.

See also
setActions

ACTION_SKIP_TO_PREVIOUS

Added in 1.1.0
public static final long ACTION_SKIP_TO_PREVIOUS = 16

Indicates this session supports the previous command.

See also
setActions

ACTION_SKIP_TO_QUEUE_ITEM

Added in 1.1.0
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

Added in 1.1.0
public static final long ACTION_STOP = 1

Indicates this session supports the stop command.

See also
setActions

CREATOR

Added in 1.1.0
public static final Parcelable.Creator<PlaybackStateCompatCREATOR

ERROR_CODE_ACTION_ABORTED

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
public static final long PLAYBACK_POSITION_UNKNOWN = -1

Use this value for the position to indicate the position is not known.

REPEAT_MODE_ALL

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
public static final int STATE_BUFFERING = 6

State indicating this item is currently buffering and will begin playing when enough data has buffered.

STATE_CONNECTING

Added in 1.1.0
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

STATE_ERROR

Added in 1.1.0
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

Added in 1.1.0
public static final int STATE_FAST_FORWARDING = 4

State indicating this item is currently fast forwarding.

STATE_NONE

Added in 1.1.0
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.

STATE_PAUSED

Added in 1.1.0
public static final int STATE_PAUSED = 2

State indicating this item is currently paused.

STATE_PLAYING

Added in 1.1.0
public static final int STATE_PLAYING = 3

State indicating this item is currently playing.

STATE_REWINDING

Added in 1.1.0
public static final int STATE_REWINDING = 5

State indicating this item is currently rewinding.

STATE_SKIPPING_TO_NEXT

Added in 1.1.0
public static final int STATE_SKIPPING_TO_NEXT = 10

State indicating the player is currently skipping to the next item.

STATE_SKIPPING_TO_PREVIOUS

Added in 1.1.0
public static final int STATE_SKIPPING_TO_PREVIOUS = 9

State indicating the player is currently skipping to the previous item.

STATE_SKIPPING_TO_QUEUE_ITEM

Added in 1.1.0
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

STATE_STOPPED

Added in 1.1.0
public static final int STATE_STOPPED = 1

State indicating this item is currently stopped.

Public methods

describeContents

Added in 1.1.0
public int describeContents()

fromPlaybackState

Added in 1.1.0
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 android.media.session.PlaybackState object, or null if none.

Returns
PlaybackStateCompat

An equivalent PlaybackStateCompat object, or null if none.

getActiveQueueItemId

Added in 1.1.0
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 UNKNOWN_ID.

getBufferedPosition

Added in 1.1.0
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

Added in 1.1.0
public List<PlaybackStateCompat.CustomActiongetCustomActions()

Get the list of custom actions.

getErrorMessage

Added in 1.1.0
public CharSequence getErrorMessage()

Get the user readable optional error message. This may be set when the state is STATE_ERROR.

See also
getErrorCode

getExtras

Added in 1.1.0
public @Nullable Bundle getExtras()

Get any custom extras that were set on this playback state.

Returns
@Nullable Bundle

The extras for this state or null.

getLastPositionUpdateTime

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
public Object getPlaybackState()

Gets the underlying framework android.media.session.PlaybackState object.

This method is only supported on API 21+.

Returns
Object

An equivalent android.media.session.PlaybackState object, or null if none.

getPosition

Added in 1.1.0
public long getPosition()

Get the playback position in ms at last position update time.

toKeyCode

Added in 1.1.0
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:

Parameters
long action

The action to be translated.

Returns
int

the key code matched to the given action.

toString

public String toString()

writeToParcel

Added in 1.1.0
public void writeToParcel(Parcel dest, int flags)