Added in API level 21

PlaybackState

class PlaybackState : Parcelable
kotlin.Any
   ↳ android.media.session.PlaybackState

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

Summary

Nested classes

Builder for PlaybackState objects.

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

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 playback speed command.

static Long

Indicates this session supports the set rating 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 Long

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

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 new destination.

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.

Inherited constants
Public methods
Int

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<PlaybackState.CustomAction!>!

Get the list of custom actions.

CharSequence!

Get a user readable 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.

Long

Get the current playback position in ms.

Int

Get the current state of playback.

Boolean

Returns whether this is considered as an active playback state.

String

Unit
writeToParcel(dest: Parcel, flags: Int)

Properties
static Parcelable.Creator<PlaybackState!>

Constants

ACTION_FAST_FORWARD

Added in API level 21
static val ACTION_FAST_FORWARD: Long

Indicates this session supports the fast forward command.

Value: 64L

ACTION_PAUSE

Added in API level 21
static val ACTION_PAUSE: Long

Indicates this session supports the pause command.

Value: 2L

ACTION_PLAY

Added in API level 21
static val ACTION_PLAY: Long

Indicates this session supports the play command.

Value: 4L

ACTION_PLAY_FROM_MEDIA_ID

Added in API level 21
static val ACTION_PLAY_FROM_MEDIA_ID: Long

Indicates this session supports the play from media id command.

Value: 1024L
Added in API level 21
static val ACTION_PLAY_FROM_SEARCH: Long

Indicates this session supports the play from search command.

Value: 2048L

ACTION_PLAY_FROM_URI

Added in API level 23
static val ACTION_PLAY_FROM_URI: Long

Indicates this session supports the play from URI command.

Value: 8192L

ACTION_PLAY_PAUSE

Added in API level 21
static val ACTION_PLAY_PAUSE: Long

Indicates this session supports the play/pause toggle command.

Value: 512L

ACTION_PREPARE

Added in API level 24
static val ACTION_PREPARE: Long

Indicates this session supports the prepare command.

Value: 16384L

ACTION_PREPARE_FROM_MEDIA_ID

Added in API level 24
static val ACTION_PREPARE_FROM_MEDIA_ID: Long

Indicates this session supports the prepare from media id command.

Value: 32768L
Added in API level 24
static val ACTION_PREPARE_FROM_SEARCH: Long

Indicates this session supports the prepare from search command.

Value: 65536L

ACTION_PREPARE_FROM_URI

Added in API level 24
static val ACTION_PREPARE_FROM_URI: Long

Indicates this session supports the prepare from URI command.

Value: 131072L

ACTION_REWIND

Added in API level 21
static val ACTION_REWIND: Long

Indicates this session supports the rewind command.

Value: 8L

ACTION_SEEK_TO

Added in API level 21
static val ACTION_SEEK_TO: Long

Indicates this session supports the seek to command.

Value: 256L

ACTION_SET_PLAYBACK_SPEED

Added in API level 31
static val ACTION_SET_PLAYBACK_SPEED: Long

Indicates this session supports the set playback speed command.

Value: 4194304L

ACTION_SET_RATING

Added in API level 21
static val ACTION_SET_RATING: Long

Indicates this session supports the set rating command.

Value: 128L

ACTION_SKIP_TO_NEXT

Added in API level 21
static val ACTION_SKIP_TO_NEXT: Long

Indicates this session supports the next command.

Value: 32L

ACTION_SKIP_TO_PREVIOUS

Added in API level 21
static val ACTION_SKIP_TO_PREVIOUS: Long

Indicates this session supports the previous command.

Value: 16L

ACTION_SKIP_TO_QUEUE_ITEM

Added in API level 21
static val ACTION_SKIP_TO_QUEUE_ITEM: Long

Indicates this session supports the skip to queue item command.

Value: 4096L

ACTION_STOP

Added in API level 21
static val ACTION_STOP: Long

Indicates this session supports the stop command.

Value: 1L

PLAYBACK_POSITION_UNKNOWN

Added in API level 21
static val PLAYBACK_POSITION_UNKNOWN: Long

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

Value: -1L

STATE_BUFFERING

Added in API level 21
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

    Added in API level 21
    static val STATE_CONNECTING: Int

    State indicating the class doing playback is currently connecting to a new destination. 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.

    Value: 8

    See Also

      STATE_ERROR

      Added in API level 21
      static val STATE_ERROR: Int

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

      Value: 7

      See Also

        STATE_FAST_FORWARDING

        Added in API level 21
        static val STATE_FAST_FORWARDING: Int

        State indicating this item is currently fast forwarding.

        Value: 4

        See Also

          STATE_NONE

          Added in API level 21
          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

          STATE_PAUSED

          Added in API level 21
          static val STATE_PAUSED: Int

          State indicating this item is currently paused.

          Value: 2

          See Also

            STATE_PLAYING

            Added in API level 21
            static val STATE_PLAYING: Int

            State indicating this item is currently playing.

            Value: 3

            See Also

              STATE_REWINDING

              Added in API level 21
              static val STATE_REWINDING: Int

              State indicating this item is currently rewinding.

              Value: 5

              See Also

                STATE_SKIPPING_TO_NEXT

                Added in API level 21
                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

                  Added in API level 21
                  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

                    Added in API level 21
                    static val STATE_SKIPPING_TO_QUEUE_ITEM: Int

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

                    Value: 11

                    See Also

                      STATE_STOPPED

                      Added in API level 21
                      static val STATE_STOPPED: Int

                      State indicating this item is currently stopped.

                      Value: 1

                      See Also

                        Public methods

                        describeContents

                        Added in API level 21
                        fun describeContents(): Int
                        Return
                        Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

                        getActions

                        Added in API level 21
                        fun getActions(): Long

                        Get the current actions available on this session. This should use a bitmask of the available actions.

                        Return
                        Long Value is either 0 or a combination of android.media.session.PlaybackState#ACTION_STOP, android.media.session.PlaybackState#ACTION_PAUSE, android.media.session.PlaybackState#ACTION_PLAY, android.media.session.PlaybackState#ACTION_REWIND, android.media.session.PlaybackState#ACTION_SKIP_TO_PREVIOUS, android.media.session.PlaybackState#ACTION_SKIP_TO_NEXT, android.media.session.PlaybackState#ACTION_FAST_FORWARD, android.media.session.PlaybackState#ACTION_SET_RATING, android.media.session.PlaybackState#ACTION_SEEK_TO, android.media.session.PlaybackState#ACTION_PLAY_PAUSE, android.media.session.PlaybackState#ACTION_PLAY_FROM_MEDIA_ID, android.media.session.PlaybackState#ACTION_PLAY_FROM_SEARCH, android.media.session.PlaybackState#ACTION_SKIP_TO_QUEUE_ITEM, android.media.session.PlaybackState#ACTION_PLAY_FROM_URI, android.media.session.PlaybackState#ACTION_PREPARE, android.media.session.PlaybackState#ACTION_PREPARE_FROM_MEDIA_ID, android.media.session.PlaybackState#ACTION_PREPARE_FROM_SEARCH, android.media.session.PlaybackState#ACTION_PREPARE_FROM_URI, and android.media.session.PlaybackState#ACTION_SET_PLAYBACK_SPEED

                        getActiveQueueItemId

                        Added in API level 21
                        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 MediaSession.QueueItem#UNKNOWN_ID.

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

                        getBufferedPosition

                        Added in API level 21
                        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 API level 21
                        fun getCustomActions(): MutableList<PlaybackState.CustomAction!>!

                        Get the list of custom actions.

                        getErrorMessage

                        Added in API level 21
                        fun getErrorMessage(): CharSequence!

                        Get a user readable error message. This should be set when the state is PlaybackState#STATE_ERROR.

                        getExtras

                        Added in API level 22
                        fun getExtras(): Bundle?

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

                        Return
                        Bundle? The extras for this state or null.

                        getLastPositionUpdateTime

                        Added in API level 21
                        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

                        Added in API level 21
                        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.

                        getPosition

                        Added in API level 21
                        fun getPosition(): Long

                        Get the current playback position in ms.

                        isActive

                        Added in API level 31
                        fun isActive(): Boolean

                        Returns whether this is considered as an active playback state.

                        The playback state is considered as an active if the state is one of the following:

                        toString

                        Added in API level 21
                        fun toString(): String
                        Return
                        String a string representation of the object.

                        writeToParcel

                        Added in API level 21
                        fun writeToParcel(
                            dest: Parcel,
                            flags: Int
                        ): Unit
                        Parameters
                        dest Parcel: The Parcel in which the object should be written. This value cannot be null.
                        flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

                        Properties

                        CREATOR

                        Added in API level 21
                        static val CREATOR: Parcelable.Creator<PlaybackState!>