PlaybackStateCompat


class PlaybackStateCompat : 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

Builder for PlaybackStateCompat objects.

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

const Long

Indicates this session supports the fast forward command.

const Long

Indicates this session supports the pause command.

const Long

Indicates this session supports the play command.

const Long

Indicates this session supports the play from media id command.

const Long

Indicates this session supports the play from search command.

const Long

Indicates this session supports the play from URI command.

const Long

Indicates this session supports the play/pause toggle command.

const Long

Indicates this session supports the prepare command.

const Long

Indicates this session supports the prepare from media id command.

const Long

Indicates this session supports the prepare from search command.

const Long

Indicates this session supports the prepare from URI command.

const Long

Indicates this session supports the rewind command.

const Long

Indicates this session supports the seek to command.

const Long

Indicates this session supports the set captioning enabled command.

const Long

Indicates this session supports the set playback speed command.

const Long

Indicates this session supports the set rating command.

const Long

Indicates this session supports the set repeat mode command.

const Long

Indicates this session supports the set shuffle mode command.

const Long

This property is deprecated.

Use ACTION_SET_SHUFFLE_MODE instead.

const Long

Indicates this session supports the next command.

const Long

Indicates this session supports the previous command.

const Long

Indicates this session supports the skip to queue item command.

const Long

Indicates this session supports the stop command.

const Parcelable.Creator<PlaybackStateCompat!>!
const Int

Error code when the action is interrupted due to some external event.

const Int

Error code when the application state is invalid to fulfill the request.

const Int

Error code when the request cannot be performed because authentication has expired.

const Int

Error code when too many concurrent streams are detected.

const Int

Error code when the requested content is already playing.

const Int

Error code when the playback navigation (previous, next) is not possible because the queue was exhausted.

const Int

Error code when the content is blocked due to being regionally unavailable.

const Int

Error code when the request is not supported by the application.

const Int

Error code when the content is blocked due to parental controls.

const Int

Error code when a premium account is required for the request to succeed.

const Int

Error code when the application cannot skip any more songs because skip limit is reached.

const Int

This is the default error code and indicates that none of the other error codes applies.

const Long

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

const Int

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

const Int

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

const Int

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

const Int

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

const Int

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

const Int

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

const Int

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

const Int

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

const Int

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

const Int

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

const Int

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

const Int

State indicating this item is currently in an error state.

const Int

State indicating this item is currently fast forwarding.

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

const Int

State indicating this item is currently paused.

const Int

State indicating this item is currently playing.

const Int

State indicating this item is currently rewinding.

const Int

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

const Int

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

const Int

State indicating the player is currently skipping to a specific item in the queue.

const Int

State indicating this item is currently stopped.

Public functions

Int
java-static PlaybackStateCompat!
fromPlaybackState(stateObj: Any!)

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.

(Mutable)List<PlaybackStateCompat.CustomAction!>!

Get the list of custom actions.

Int

Get the error code.

CharSequence!

Get the user readable optional error message.

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.

Any!

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.

java-static Int
toKeyCode(action: Long)

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

String!
Unit
writeToParcel(dest: Parcel!, flags: Int)

Constants

ACTION_FAST_FORWARD

Added in 1.1.0
const val ACTION_FAST_FORWARD = 64: Long

Indicates this session supports the fast forward command.

See also
setActions

ACTION_PAUSE

Added in 1.1.0
const val ACTION_PAUSE = 2: Long

Indicates this session supports the pause command.

See also
setActions

ACTION_PLAY

Added in 1.1.0
const val ACTION_PLAY = 4: Long

Indicates this session supports the play command.

See also
setActions

ACTION_PLAY_FROM_MEDIA_ID

Added in 1.1.0
const val ACTION_PLAY_FROM_MEDIA_ID = 1024: Long

Indicates this session supports the play from media id command.

See also
setActions

ACTION_PLAY_FROM_SEARCH

Added in 1.1.0
const val ACTION_PLAY_FROM_SEARCH = 2048: Long

Indicates this session supports the play from search command.

See also
setActions

ACTION_PLAY_FROM_URI

Added in 1.1.0
const val ACTION_PLAY_FROM_URI = 8192: Long

Indicates this session supports the play from URI command.

See also
setActions

ACTION_PLAY_PAUSE

Added in 1.1.0
const val ACTION_PLAY_PAUSE = 512: Long

Indicates this session supports the play/pause toggle command.

See also
setActions

ACTION_PREPARE

Added in 1.1.0
const val ACTION_PREPARE = 16384: Long

Indicates this session supports the prepare command.

See also
setActions

ACTION_PREPARE_FROM_MEDIA_ID

Added in 1.1.0
const val ACTION_PREPARE_FROM_MEDIA_ID = 32768: Long

Indicates this session supports the prepare from media id command.

See also
setActions

ACTION_PREPARE_FROM_SEARCH

Added in 1.1.0
const val ACTION_PREPARE_FROM_SEARCH = 65536: Long

Indicates this session supports the prepare from search command.

See also
setActions

ACTION_PREPARE_FROM_URI

Added in 1.1.0
const val ACTION_PREPARE_FROM_URI = 131072: Long

Indicates this session supports the prepare from URI command.

See also
setActions

ACTION_REWIND

Added in 1.1.0
const val ACTION_REWIND = 8: Long

Indicates this session supports the rewind command.

See also
setActions

ACTION_SEEK_TO

Added in 1.1.0
const val ACTION_SEEK_TO = 256: Long

Indicates this session supports the seek to command.

See also
setActions

ACTION_SET_CAPTIONING_ENABLED

Added in 1.1.0
const val ACTION_SET_CAPTIONING_ENABLED = 1048576: Long

Indicates this session supports the set captioning enabled command.

See also
setActions

ACTION_SET_PLAYBACK_SPEED

Added in 1.3.0
const val ACTION_SET_PLAYBACK_SPEED = 4194304: Long

Indicates this session supports the set playback speed command.

See also
setActions

ACTION_SET_RATING

Added in 1.1.0
const val ACTION_SET_RATING = 128: Long

Indicates this session supports the set rating command.

See also
setActions

ACTION_SET_REPEAT_MODE

Added in 1.1.0
const val ACTION_SET_REPEAT_MODE = 262144: Long

Indicates this session supports the set repeat mode command.

See also
setActions

ACTION_SET_SHUFFLE_MODE

Added in 1.1.0
const val ACTION_SET_SHUFFLE_MODE = 2097152: Long

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
const val ACTION_SET_SHUFFLE_MODE_ENABLED = 524288: Long

Indicates this session supports the set shuffle mode enabled command.

See also
setActions

ACTION_SKIP_TO_NEXT

Added in 1.1.0
const val ACTION_SKIP_TO_NEXT = 32: Long

Indicates this session supports the next command.

See also
setActions

ACTION_SKIP_TO_PREVIOUS

Added in 1.1.0
const val ACTION_SKIP_TO_PREVIOUS = 16: Long

Indicates this session supports the previous command.

See also
setActions

ACTION_SKIP_TO_QUEUE_ITEM

Added in 1.1.0
const val ACTION_SKIP_TO_QUEUE_ITEM = 4096: Long

Indicates this session supports the skip to queue item command.

See also
setActions

ACTION_STOP

Added in 1.1.0
const val ACTION_STOP = 1: Long

Indicates this session supports the stop command.

See also
setActions

CREATOR

Added in 1.1.0
const val CREATORParcelable.Creator<PlaybackStateCompat!>!

ERROR_CODE_ACTION_ABORTED

Added in 1.1.0
const val ERROR_CODE_ACTION_ABORTED = 10: Int

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
const val ERROR_CODE_APP_ERROR = 1: Int

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
const val ERROR_CODE_AUTHENTICATION_EXPIRED = 3: Int

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
const val ERROR_CODE_CONCURRENT_STREAM_LIMIT = 5: Int

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
const val ERROR_CODE_CONTENT_ALREADY_PLAYING = 8: Int

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
const val ERROR_CODE_END_OF_QUEUE = 11: Int

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
const val ERROR_CODE_NOT_AVAILABLE_IN_REGION = 7: Int

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
const val ERROR_CODE_NOT_SUPPORTED = 2: Int

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
const val ERROR_CODE_PARENTAL_CONTROL_RESTRICTED = 6: Int

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
const val ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED = 4: Int

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
const val ERROR_CODE_SKIP_LIMIT_REACHED = 9: Int

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
const val ERROR_CODE_UNKNOWN_ERROR = 0: Int

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
const val PLAYBACK_POSITION_UNKNOWN = -1: Long

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

REPEAT_MODE_ALL

Added in 1.1.0
const val REPEAT_MODE_ALL = 2: Int

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
const val REPEAT_MODE_GROUP = 3: Int

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
const val REPEAT_MODE_INVALID = -1: Int

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

REPEAT_MODE_NONE

Added in 1.1.0
const val REPEAT_MODE_NONE = 0: Int

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
const val REPEAT_MODE_ONE = 1: Int

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
const val SHUFFLE_MODE_ALL = 1: Int

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
const val SHUFFLE_MODE_GROUP = 2: Int

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
const val SHUFFLE_MODE_INVALID = -1: Int

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

SHUFFLE_MODE_NONE

Added in 1.1.0
const val SHUFFLE_MODE_NONE = 0: Int

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

STATE_BUFFERING

Added in 1.1.0
const val STATE_BUFFERING = 6: Int

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

STATE_CONNECTING

Added in 1.1.0
const val STATE_CONNECTING = 8: Int

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
const val STATE_ERROR = 7: Int

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
const val STATE_FAST_FORWARDING = 4: Int

State indicating this item is currently fast forwarding.

STATE_NONE

Added in 1.1.0
const val STATE_NONE = 0: 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.

STATE_PAUSED

Added in 1.1.0
const val STATE_PAUSED = 2: Int

State indicating this item is currently paused.

STATE_PLAYING

Added in 1.1.0
const val STATE_PLAYING = 3: Int

State indicating this item is currently playing.

STATE_REWINDING

Added in 1.1.0
const val STATE_REWINDING = 5: Int

State indicating this item is currently rewinding.

STATE_SKIPPING_TO_NEXT

Added in 1.1.0
const val STATE_SKIPPING_TO_NEXT = 10: Int

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

STATE_SKIPPING_TO_PREVIOUS

Added in 1.1.0
const val STATE_SKIPPING_TO_PREVIOUS = 9: Int

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

STATE_SKIPPING_TO_QUEUE_ITEM

Added in 1.1.0
const val STATE_SKIPPING_TO_QUEUE_ITEM = 11: Int

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
const val STATE_STOPPED = 1: Int

State indicating this item is currently stopped.

Public functions

describeContents

Added in 1.1.0
fun describeContents(): Int

fromPlaybackState

Added in 1.1.0
java-static fun fromPlaybackState(stateObj: Any!): PlaybackStateCompat!

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

This method is only supported on API 21+.

Parameters
stateObj: Any!

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
fun getActiveQueueItemId(): Long

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
fun getBufferedPosition(): Long

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
fun getCustomActions(): (Mutable)List<PlaybackStateCompat.CustomAction!>!

Get the list of custom actions.

getErrorMessage

Added in 1.1.0
fun getErrorMessage(): CharSequence!

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
fun getExtras(): Bundle?

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

Returns
Bundle?

The extras for this state or null.

getLastPositionUpdateTime

Added in 1.1.0
fun getLastPositionUpdateTime(): Long

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
fun getPlaybackSpeed(): Float

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
fun getPlaybackState(): Any!

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

This method is only supported on API 21+.

Returns
Any!

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

getPosition

Added in 1.1.0
fun getPosition(): Long

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

toKeyCode

Added in 1.1.0
java-static fun toKeyCode(action: Long): Int

Translates a given action into a matched key code defined in KeyEvent. The given action should be one of the following:

Parameters
action: Long

The action to be translated.

Returns
Int

the key code matched to the given action.

toString

fun toString(): String!

writeToParcel

Added in 1.1.0
fun writeToParcel(dest: Parcel!, flags: Int): Unit