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 |
|
Builder for |
Constants |
|
---|---|
const Long |
ACTION_FAST_FORWARD = 64 Indicates this session supports the fast forward command. |
const Long |
ACTION_PAUSE = 2 Indicates this session supports the pause command. |
const Long |
ACTION_PLAY = 4 Indicates this session supports the play command. |
const Long |
ACTION_PLAY_FROM_MEDIA_ID = 1024 Indicates this session supports the play from media id command. |
const Long |
ACTION_PLAY_FROM_SEARCH = 2048 Indicates this session supports the play from search command. |
const Long |
ACTION_PLAY_FROM_URI = 8192 Indicates this session supports the play from URI command. |
const Long |
ACTION_PLAY_PAUSE = 512 Indicates this session supports the play/pause toggle command. |
const Long |
ACTION_PREPARE = 16384 Indicates this session supports the prepare command. |
const Long |
ACTION_PREPARE_FROM_MEDIA_ID = 32768 Indicates this session supports the prepare from media id command. |
const Long |
ACTION_PREPARE_FROM_SEARCH = 65536 Indicates this session supports the prepare from search command. |
const Long |
ACTION_PREPARE_FROM_URI = 131072 Indicates this session supports the prepare from URI command. |
const Long |
ACTION_REWIND = 8 Indicates this session supports the rewind command. |
const Long |
ACTION_SEEK_TO = 256 Indicates this session supports the seek to command. |
const Long |
ACTION_SET_CAPTIONING_ENABLED = 1048576 Indicates this session supports the set captioning enabled command. |
const Long |
ACTION_SET_PLAYBACK_SPEED = 4194304 Indicates this session supports the set playback speed command. |
const Long |
ACTION_SET_RATING = 128 Indicates this session supports the set rating command. |
const Long |
ACTION_SET_REPEAT_MODE = 262144 Indicates this session supports the set repeat mode command. |
const Long |
ACTION_SET_SHUFFLE_MODE = 2097152 Indicates this session supports the set shuffle mode command. |
const Long |
ACTION_SET_SHUFFLE_MODE_ENABLED = 524288 This property is deprecated. Use |
const Long |
ACTION_SKIP_TO_NEXT = 32 Indicates this session supports the next command. |
const Long |
Indicates this session supports the previous command. |
const Long |
ACTION_SKIP_TO_QUEUE_ITEM = 4096 Indicates this session supports the skip to queue item command. |
const Long |
ACTION_STOP = 1 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 |
REPEAT_MODE_ALL = 2 Use this value with |
const Int |
Use this value with |
const Int |
REPEAT_MODE_INVALID = -1
|
const Int |
REPEAT_MODE_NONE = 0 Use this value with |
const Int |
REPEAT_MODE_ONE = 1 Use this value with |
const Int |
SHUFFLE_MODE_ALL = 1 Use this value with |
const Int |
Use this value with |
const Int |
SHUFFLE_MODE_INVALID = -1
|
const Int |
Use this value with |
const Int |
STATE_BUFFERING = 6 State indicating this item is currently buffering and will begin playing when enough data has buffered. |
const Int |
STATE_CONNECTING = 8 State indicating the class doing playback is currently connecting to a route. |
const Int |
STATE_ERROR = 7 State indicating this item is currently in an error state. |
const Int |
State indicating this item is currently fast forwarding. |
const 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. |
const Int |
STATE_PAUSED = 2 State indicating this item is currently paused. |
const Int |
STATE_PLAYING = 3 State indicating this item is currently playing. |
const Int |
STATE_REWINDING = 5 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_STOPPED = 1 State indicating this item is currently stopped. |
Public functions |
|
---|---|
Int |
|
java-static PlaybackStateCompat! |
fromPlaybackState(stateObj: Any!) 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. |
(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 |
Long |
Get the playback position in ms at last position update time. |
Int |
getState() Get the current state of playback. |
java-static Int |
Translates a given action into a matched key code defined in |
String! |
toString() |
Unit |
writeToParcel(dest: Parcel!, flags: Int) |
Constants
ACTION_FAST_FORWARD
const val ACTION_FAST_FORWARD = 64: Long
Indicates this session supports the fast forward command.
See also | |
---|---|
setActions |
ACTION_PAUSE
const val ACTION_PAUSE = 2: Long
Indicates this session supports the pause command.
See also | |
---|---|
setActions |
ACTION_PLAY
const val ACTION_PLAY = 4: Long
Indicates this session supports the play command.
See also | |
---|---|
setActions |
ACTION_PLAY_FROM_MEDIA_ID
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
const val ACTION_PLAY_FROM_SEARCH = 2048: Long
Indicates this session supports the play from search command.
See also | |
---|---|
setActions |
ACTION_PLAY_FROM_URI
const val ACTION_PLAY_FROM_URI = 8192: Long
Indicates this session supports the play from URI command.
See also | |
---|---|
setActions |
ACTION_PLAY_PAUSE
const val ACTION_PLAY_PAUSE = 512: Long
Indicates this session supports the play/pause toggle command.
See also | |
---|---|
setActions |
ACTION_PREPARE
const val ACTION_PREPARE = 16384: Long
Indicates this session supports the prepare command.
See also | |
---|---|
setActions |
ACTION_PREPARE_FROM_MEDIA_ID
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
const val ACTION_PREPARE_FROM_SEARCH = 65536: Long
Indicates this session supports the prepare from search command.
See also | |
---|---|
setActions |
ACTION_PREPARE_FROM_URI
const val ACTION_PREPARE_FROM_URI = 131072: Long
Indicates this session supports the prepare from URI command.
See also | |
---|---|
setActions |
ACTION_REWIND
const val ACTION_REWIND = 8: Long
Indicates this session supports the rewind command.
See also | |
---|---|
setActions |
ACTION_SEEK_TO
const val ACTION_SEEK_TO = 256: Long
Indicates this session supports the seek to command.
See also | |
---|---|
setActions |
ACTION_SET_CAPTIONING_ENABLED
const val ACTION_SET_CAPTIONING_ENABLED = 1048576: Long
Indicates this session supports the set captioning enabled command.
See also | |
---|---|
setActions |
ACTION_SET_PLAYBACK_SPEED
const val ACTION_SET_PLAYBACK_SPEED = 4194304: Long
Indicates this session supports the set playback speed command.
See also | |
---|---|
setActions |
ACTION_SET_RATING
const val ACTION_SET_RATING = 128: Long
Indicates this session supports the set rating command.
See also | |
---|---|
setActions |
ACTION_SET_REPEAT_MODE
const val ACTION_SET_REPEAT_MODE = 262144: Long
Indicates this session supports the set repeat mode command.
See also | |
---|---|
setActions |
ACTION_SET_SHUFFLE_MODE
const val ACTION_SET_SHUFFLE_MODE = 2097152: Long
Indicates this session supports the set shuffle mode command.
See also | |
---|---|
setActions |
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
const val ACTION_SKIP_TO_NEXT = 32: Long
Indicates this session supports the next command.
See also | |
---|---|
setActions |
ACTION_SKIP_TO_PREVIOUS
const val ACTION_SKIP_TO_PREVIOUS = 16: Long
Indicates this session supports the previous command.
See also | |
---|---|
setActions |
ACTION_SKIP_TO_QUEUE_ITEM
const val ACTION_SKIP_TO_QUEUE_ITEM = 4096: Long
Indicates this session supports the skip to queue item command.
See also | |
---|---|
setActions |
ACTION_STOP
const val ACTION_STOP = 1: Long
Indicates this session supports the stop command.
See also | |
---|---|
setActions |
ERROR_CODE_ACTION_ABORTED
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
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
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
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
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
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
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
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
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
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
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
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
const val PLAYBACK_POSITION_UNKNOWN = -1: Long
Use this value for the position to indicate the position is not known.
REPEAT_MODE_ALL
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
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
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
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
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
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
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
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
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
const val STATE_BUFFERING = 6: Int
State indicating this item is currently buffering and will begin playing when enough data has buffered.
See also | |
---|---|
PlaybackStateCompat.Builder |
STATE_CONNECTING
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
See also | |
---|---|
PlaybackStateCompat.Builder |
STATE_ERROR
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
const val STATE_FAST_FORWARDING = 4: Int
State indicating this item is currently fast forwarding.
See also | |
---|---|
PlaybackStateCompat.Builder |
STATE_NONE
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.
See also | |
---|---|
PlaybackStateCompat.Builder |
STATE_PAUSED
const val STATE_PAUSED = 2: Int
State indicating this item is currently paused.
See also | |
---|---|
PlaybackStateCompat.Builder |
STATE_PLAYING
const val STATE_PLAYING = 3: Int
State indicating this item is currently playing.
See also | |
---|---|
PlaybackStateCompat.Builder |
STATE_REWINDING
const val STATE_REWINDING = 5: Int
State indicating this item is currently rewinding.
See also | |
---|---|
PlaybackStateCompat.Builder |
STATE_SKIPPING_TO_NEXT
const val STATE_SKIPPING_TO_NEXT = 10: Int
State indicating the player is currently skipping to the next item.
See also | |
---|---|
PlaybackStateCompat.Builder |
STATE_SKIPPING_TO_PREVIOUS
const val STATE_SKIPPING_TO_PREVIOUS = 9: Int
State indicating the player is currently skipping to the previous item.
See also | |
---|---|
PlaybackStateCompat.Builder |
STATE_SKIPPING_TO_QUEUE_ITEM
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
See also | |
---|---|
PlaybackStateCompat.Builder |
STATE_STOPPED
const val STATE_STOPPED = 1: Int
State indicating this item is currently stopped.
See also | |
---|---|
PlaybackStateCompat.Builder |
Public functions
fromPlaybackState
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 |
Returns | |
---|---|
PlaybackStateCompat! |
An equivalent |
getActions
fun getActions(): Long
Get the current actions available on this session. This should use a bitmask of the available actions.
ACTION_SKIP_TO_PREVIOUS
ACTION_REWIND
ACTION_PLAY
ACTION_PLAY_PAUSE
ACTION_PAUSE
ACTION_STOP
ACTION_FAST_FORWARD
ACTION_SKIP_TO_NEXT
ACTION_SEEK_TO
ACTION_SET_RATING
ACTION_PLAY_FROM_MEDIA_ID
ACTION_PLAY_FROM_SEARCH
ACTION_SKIP_TO_QUEUE_ITEM
ACTION_PLAY_FROM_URI
ACTION_PREPARE
ACTION_PREPARE_FROM_MEDIA_ID
ACTION_PREPARE_FROM_SEARCH
ACTION_PREPARE_FROM_URI
ACTION_SET_REPEAT_MODE
ACTION_SET_SHUFFLE_MODE
ACTION_SET_CAPTIONING_ENABLED
ACTION_SET_PLAYBACK_SPEED
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 UNKNOWN_ID
.
Returns | |
---|---|
Long |
The id of the currently active item in the queue or |
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(): (Mutable)List<PlaybackStateCompat.CustomAction!>!
Get the list of custom actions.
getErrorCode
fun getErrorCode(): Int
Get the error code. This should be set when the state is STATE_ERROR
.
getErrorMessage
fun getErrorMessage(): CharSequence!
Get the user readable optional error message. This may be set when the state is STATE_ERROR
.
See also | |
---|---|
getErrorCode |
getExtras
fun getExtras(): Bundle?
Get any custom extras that were set on this playback state.
Returns | |
---|---|
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;
Returns | |
---|---|
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.
Returns | |
---|---|
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+.
Returns | |
---|---|
Any! |
An equivalent |
getPosition
fun getPosition(): Long
Get the playback position in ms at last position update time.
getState
fun getState(): Int
Get the current state of playback. One of the following:
toKeyCode
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:
ACTION_PLAY
ACTION_PAUSE
ACTION_SKIP_TO_NEXT
ACTION_SKIP_TO_PREVIOUS
ACTION_STOP
ACTION_FAST_FORWARD
ACTION_REWIND
ACTION_PLAY_PAUSE
Parameters | |
---|---|
action: Long |
The action to be translated. |
Returns | |
---|---|
Int |
the key code matched to the given action. |