PlaybackStateCompat

class PlaybackStateCompat : Parcelable
kotlin.Any
   ↳ android.support.v4.media.session.PlaybackStateCompat

Playback state for a MediaSessionCompat. This includes a state like PlaybackStateCompat#STATE_PLAYING, the current playback position, and the current control capabilities.

Summary

Nested classes

Builder for PlaybackStateCompat objects.

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

Constants

static Long

Indicates this session supports the fast forward command.

static Long

Indicates this session supports the pause command.

static Long

Indicates this session supports the play command.

static Long

Indicates this session supports the play from media id command.

static Long

Indicates this session supports the play from search command.

static Long

Indicates this session supports the play from URI command.

static Long

Indicates this session supports the play/pause toggle command.

static Long

Indicates this session supports the prepare command.

static Long

Indicates this session supports the prepare from media id command.

static Long

Indicates this session supports the prepare from search command.

static Long

Indicates this session supports the prepare from URI command.

static Long

Indicates this session supports the rewind command.

static Long

Indicates this session supports the seek to command.

static Long

Indicates this session supports the set captioning enabled command.

static Long

Indicates this session supports the set rating command.

static Long

Indicates this session supports the set repeat mode command.

static Long

Indicates this session supports the set shuffle mode command.

static Long

Indicates this session supports the set shuffle mode enabled command.

static Long

Indicates this session supports the next command.

static Long

Indicates this session supports the previous command.

static Long

Indicates this session supports the skip to queue item command.

static Long

Indicates this session supports the stop command.

static Int

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

static Int

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

static Int

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

static Int

Error code when too many concurrent streams are detected.

static Int

Error code when the requested content is already playing.

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Long

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

State indicating this item is currently in an error state.

static Int

State indicating this item is currently fast forwarding.

static 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 Int

State indicating this item is currently paused.

static Int

State indicating this item is currently playing.

static Int

State indicating this item is currently rewinding.

static Int

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

static Int

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

static Int

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

static Int

State indicating this item is currently stopped.

Public methods

Int

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.

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

static Int
toKeyCode(action: Long)

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

String

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

Properties

static Creator<PlaybackStateCompat!>!

Constants

ACTION_FAST_FORWARD

static val ACTION_FAST_FORWARD: Long

Indicates this session supports the fast forward command.

Value: 1 << 6

ACTION_PAUSE

static val ACTION_PAUSE: Long

Indicates this session supports the pause command.

Value: 1 << 1

ACTION_PLAY

static val ACTION_PLAY: Long

Indicates this session supports the play command.

Value: 1 << 2

ACTION_PLAY_FROM_MEDIA_ID

static val ACTION_PLAY_FROM_MEDIA_ID: Long

Indicates this session supports the play from media id command.

Value: 1 << 10

ACTION_PLAY_FROM_SEARCH

static val ACTION_PLAY_FROM_SEARCH: Long

Indicates this session supports the play from search command.

Value: 1 << 11

ACTION_PLAY_FROM_URI

static val ACTION_PLAY_FROM_URI: Long

Indicates this session supports the play from URI command.

Value: 1 << 13

ACTION_PLAY_PAUSE

static val ACTION_PLAY_PAUSE: Long

Indicates this session supports the play/pause toggle command.

Value: 1 << 9

ACTION_PREPARE

static val ACTION_PREPARE: Long

Indicates this session supports the prepare command.

Value: 1 << 14

ACTION_PREPARE_FROM_MEDIA_ID

static val ACTION_PREPARE_FROM_MEDIA_ID: Long

Indicates this session supports the prepare from media id command.

Value: 1 << 15

ACTION_PREPARE_FROM_SEARCH

static val ACTION_PREPARE_FROM_SEARCH: Long

Indicates this session supports the prepare from search command.

Value: 1 << 16

ACTION_PREPARE_FROM_URI

static val ACTION_PREPARE_FROM_URI: Long

Indicates this session supports the prepare from URI command.

Value: 1 << 17

ACTION_REWIND

static val ACTION_REWIND: Long

Indicates this session supports the rewind command.

Value: 1 << 3

ACTION_SEEK_TO

static val ACTION_SEEK_TO: Long

Indicates this session supports the seek to command.

Value: 1 << 8

ACTION_SET_CAPTIONING_ENABLED

static val ACTION_SET_CAPTIONING_ENABLED: Long

Indicates this session supports the set captioning enabled command.

Value: 1 << 20

ACTION_SET_RATING

static val ACTION_SET_RATING: Long

Indicates this session supports the set rating command.

Value: 1 << 7

ACTION_SET_REPEAT_MODE

static val ACTION_SET_REPEAT_MODE: Long

Indicates this session supports the set repeat mode command.

Value: 1 << 18

ACTION_SET_SHUFFLE_MODE

static val ACTION_SET_SHUFFLE_MODE: Long

Indicates this session supports the set shuffle mode command.

Value: 1 << 21

ACTION_SET_SHUFFLE_MODE_ENABLED

static val ACTION_SET_SHUFFLE_MODE_ENABLED: Long

Deprecated: Use ACTION_SET_SHUFFLE_MODE instead.

Indicates this session supports the set shuffle mode enabled command.

Value: 1 << 19

ACTION_SKIP_TO_NEXT

static val ACTION_SKIP_TO_NEXT: Long

Indicates this session supports the next command.

Value: 1 << 5

ACTION_SKIP_TO_PREVIOUS

static val ACTION_SKIP_TO_PREVIOUS: Long

Indicates this session supports the previous command.

Value: 1 << 4

ACTION_SKIP_TO_QUEUE_ITEM

static val ACTION_SKIP_TO_QUEUE_ITEM: Long

Indicates this session supports the skip to queue item command.

Value: 1 << 12

ACTION_STOP

static val ACTION_STOP: Long

Indicates this session supports the stop command.

Value: 1 << 0

ERROR_CODE_ACTION_ABORTED

static val ERROR_CODE_ACTION_ABORTED: Int

Error code when the action is interrupted due to some external event. The error code should be set when entering STATE_ERROR.

Value: 10

ERROR_CODE_APP_ERROR

static val ERROR_CODE_APP_ERROR: Int

Error code when the application state is invalid to fulfill the request. The error code should be set when entering STATE_ERROR.

Value: 1

ERROR_CODE_AUTHENTICATION_EXPIRED

static val ERROR_CODE_AUTHENTICATION_EXPIRED: Int

Error code when the request cannot be performed because authentication has expired. The error code should be set when entering STATE_ERROR.

Value: 3

ERROR_CODE_CONCURRENT_STREAM_LIMIT

static val ERROR_CODE_CONCURRENT_STREAM_LIMIT: Int

Error code when too many concurrent streams are detected. The error code should be set when entering STATE_ERROR.

Value: 5

ERROR_CODE_CONTENT_ALREADY_PLAYING

static val ERROR_CODE_CONTENT_ALREADY_PLAYING: Int

Error code when the requested content is already playing. The error code should be set when entering STATE_ERROR.

Value: 8

ERROR_CODE_END_OF_QUEUE

static val ERROR_CODE_END_OF_QUEUE: 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.

Value: 11

ERROR_CODE_NOT_AVAILABLE_IN_REGION

static val ERROR_CODE_NOT_AVAILABLE_IN_REGION: Int

Error code when the content is blocked due to being regionally unavailable. The error code should be set when entering STATE_ERROR.

Value: 7

ERROR_CODE_NOT_SUPPORTED

static val ERROR_CODE_NOT_SUPPORTED: Int

Error code when the request is not supported by the application. The error code should be set when entering STATE_ERROR.

Value: 2

ERROR_CODE_PARENTAL_CONTROL_RESTRICTED

static val ERROR_CODE_PARENTAL_CONTROL_RESTRICTED: Int

Error code when the content is blocked due to parental controls. The error code should be set when entering STATE_ERROR.

Value: 6

ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED

static val ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED: Int

Error code when a premium account is required for the request to succeed. The error code should be set when entering STATE_ERROR.

Value: 4

ERROR_CODE_SKIP_LIMIT_REACHED

static val ERROR_CODE_SKIP_LIMIT_REACHED: 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.

Value: 9

ERROR_CODE_UNKNOWN_ERROR

static val ERROR_CODE_UNKNOWN_ERROR: 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.

Value: 0

PLAYBACK_POSITION_UNKNOWN

static val PLAYBACK_POSITION_UNKNOWN: Long

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

Value: -1

REPEAT_MODE_ALL

static val REPEAT_MODE_ALL: Int

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

Value: 2

REPEAT_MODE_GROUP

static val REPEAT_MODE_GROUP: Int

Use this value with MediaControllerCompat.TransportControls#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.

Value: 3

REPEAT_MODE_INVALID

static val REPEAT_MODE_INVALID: Int

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

Value: -1

REPEAT_MODE_NONE

static val REPEAT_MODE_NONE: Int

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

Value: 0

REPEAT_MODE_ONE

static val REPEAT_MODE_ONE: Int

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

Value: 1

SHUFFLE_MODE_ALL

static val SHUFFLE_MODE_ALL: Int

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

Value: 1

SHUFFLE_MODE_GROUP

static val SHUFFLE_MODE_GROUP: Int

Use this value with MediaControllerCompat.TransportControls#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.

Value: 2

SHUFFLE_MODE_INVALID

static val SHUFFLE_MODE_INVALID: Int

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

Value: -1

SHUFFLE_MODE_NONE

static val SHUFFLE_MODE_NONE: Int

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

Value: 0

STATE_BUFFERING

static val STATE_BUFFERING: Int

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

Value: 6

See Also

STATE_CONNECTING

static val STATE_CONNECTING: 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

Value: 8

See Also

STATE_ERROR

static val STATE_ERROR: Int

State indicating this item is currently in an error state. The error code should also be set when entering this state.

Value: 7

STATE_FAST_FORWARDING

static val STATE_FAST_FORWARDING: Int

State indicating this item is currently fast forwarding.

Value: 4

See Also

STATE_NONE

static val STATE_NONE: 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.

Value: 0

See Also

STATE_PAUSED

static val STATE_PAUSED: Int

State indicating this item is currently paused.

Value: 2

See Also

STATE_PLAYING

static val STATE_PLAYING: Int

State indicating this item is currently playing.

Value: 3

See Also

STATE_REWINDING

static val STATE_REWINDING: Int

State indicating this item is currently rewinding.

Value: 5

See Also

STATE_SKIPPING_TO_NEXT

static val STATE_SKIPPING_TO_NEXT: Int

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

Value: 10

See Also

STATE_SKIPPING_TO_PREVIOUS

static val STATE_SKIPPING_TO_PREVIOUS: Int

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

Value: 9

See Also

STATE_SKIPPING_TO_QUEUE_ITEM

static val STATE_SKIPPING_TO_QUEUE_ITEM: 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

Value: 11

See Also

STATE_STOPPED

static val STATE_STOPPED: Int

State indicating this item is currently stopped.

Value: 1

See Also

Public methods

describeContents

fun describeContents(): Int

fromPlaybackState

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.
Return
PlaybackStateCompat!: An equivalent PlaybackStateCompat object, or null if none.

getActiveQueueItemId

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 MediaSessionCompat.QueueItem#UNKNOWN_ID.

Return
Long: The id of the currently active item in the queue or MediaSessionCompat.QueueItem#UNKNOWN_ID.

getBufferedPosition

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

fun getCustomActions(): MutableList<PlaybackStateCompat.CustomAction!>!

Get the list of custom actions.

getErrorMessage

fun getErrorMessage(): CharSequence!

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

See Also

getExtras

@Nullable fun getExtras(): Bundle?

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

Return
Bundle?: The extras for this state or null.

getLastPositionUpdateTime

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;

Return
Long: The last time the position was updated.

getPlaybackSpeed

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.

Return
Float: The current speed of playback.

getPlaybackState

fun getPlaybackState(): Any!

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

This method is only supported on API 21+.

Return
Any!: An equivalent android.media.session.PlaybackState object, or null if none.

getPosition

fun getPosition(): Long

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

toKeyCode

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.
Return
Int: the key code matched to the given action.

toString

fun toString(): String

writeToParcel

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

Properties

CREATOR

static val CREATOR: Creator<PlaybackStateCompat!>!