PlaybackStateCompat

Added in 1.1.0
Deprecated in 1.8.0

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

This class is deprecated.

androidx.media is deprecated.

public final class PlaybackStateCompat.CustomAction implements Parcelable

This class is deprecated.

androidx.media is deprecated.

This class is deprecated. Deprecated in Java

Constants

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated.

Use ACTION_SET_SHUFFLE_MODE instead.

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final Parcelable.Creator<PlaybackStateCompat>

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final long

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

Public methods

int

This method is deprecated. Deprecated in Java

static PlaybackStateCompat

This method is deprecated. Deprecated in Java

long

This method is deprecated. Deprecated in Java

long

This method is deprecated. Deprecated in Java

long

This method is deprecated. Deprecated in Java

List<PlaybackStateCompat.CustomAction>

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

CharSequence

This method is deprecated. Deprecated in Java

@Nullable Bundle

This method is deprecated. Deprecated in Java

long

This method is deprecated. Deprecated in Java

float

This method is deprecated. Deprecated in Java

Object

This method is deprecated. Deprecated in Java

long

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

static int
toKeyCode(long action)

This method is deprecated. Deprecated in Java

String

This method is deprecated. Deprecated in Java

void
writeToParcel(Parcel dest, int flags)

This method is deprecated. Deprecated in Java

Inherited Constants

From android.os.Parcelable
static final int

This field is deprecated. Deprecated in Java

static final int

This field is deprecated. Deprecated in Java

Constants

ACTION_FAST_FORWARD

Added in 1.1.0
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.0
public static final long ACTION_STOP = 1

Indicates this session supports the stop command.

See also
setActions

CREATOR

Added in 1.1.0
Deprecated in 1.8.0
public static final Parcelable.Creator<PlaybackStateCompat> CREATOR

ERROR_CODE_ACTION_ABORTED

Added in 1.1.0
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.0
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
setState

STATE_CONNECTING

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

See also
setState

STATE_ERROR

Added in 1.1.0
Deprecated in 1.8.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
Deprecated in 1.8.0
public static final int STATE_FAST_FORWARDING = 4

State indicating this item is currently fast forwarding.

See also
setState

STATE_NONE

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

See also
setState

STATE_PAUSED

Added in 1.1.0
Deprecated in 1.8.0
public static final int STATE_PAUSED = 2

State indicating this item is currently paused.

See also
setState

STATE_PLAYING

Added in 1.1.0
Deprecated in 1.8.0
public static final int STATE_PLAYING = 3

State indicating this item is currently playing.

See also
setState

STATE_REWINDING

Added in 1.1.0
Deprecated in 1.8.0
public static final int STATE_REWINDING = 5

State indicating this item is currently rewinding.

See also
setState

STATE_SKIPPING_TO_NEXT

Added in 1.1.0
Deprecated in 1.8.0
public static final int STATE_SKIPPING_TO_NEXT = 10

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

See also
setState

STATE_SKIPPING_TO_PREVIOUS

Added in 1.1.0
Deprecated in 1.8.0
public static final int STATE_SKIPPING_TO_PREVIOUS = 9

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

See also
setState

STATE_SKIPPING_TO_QUEUE_ITEM

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

See also
setState

STATE_STOPPED

Added in 1.1.0
Deprecated in 1.8.0
public static final int STATE_STOPPED = 1

State indicating this item is currently stopped.

See also
setState

Public methods

describeContents

Added in 1.1.0
Deprecated in 1.8.0
public int describeContents()

fromPlaybackState

Added in 1.1.0
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.0
public List<PlaybackStateCompat.CustomAction> getCustomActions()

Get the list of custom actions.

getErrorMessage

Added in 1.1.0
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.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
Deprecated in 1.8.0
public long getPosition()

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

getState

Added in 1.1.0
Deprecated in 1.8.0
public int getState()

Get the current state of playback. One of the following:

toKeyCode

Added in 1.1.0
Deprecated in 1.8.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
Deprecated in 1.8.0
public void writeToParcel(Parcel dest, int flags)