Android APIs
public final class

PlaybackStateCompat

extends Object
implements Parcelable
java.lang.Object
   ↳ android.support.v4.media.session.PlaybackStateCompat

Class Overview

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

Summary

Nested Classes
class PlaybackStateCompat.Builder Builder for PlaybackStateCompat objects. 
class PlaybackStateCompat.CustomAction CustomActions can be used to extend the capabilities of the standard transport controls by exposing app specific actions to Controllers
Constants
long ACTION_FAST_FORWARD Indicates this session supports the fast forward command.
long ACTION_PAUSE Indicates this session supports the pause command.
long ACTION_PLAY Indicates this session supports the play command.
long ACTION_PLAY_FROM_MEDIA_ID Indicates this session supports the play from media id command.
long ACTION_PLAY_FROM_SEARCH Indicates this session supports the play from search command.
long ACTION_PLAY_PAUSE Indicates this session supports the play/pause toggle command.
long ACTION_REWIND Indicates this session supports the rewind command.
long ACTION_SEEK_TO Indicates this session supports the seek to command.
long ACTION_SET_RATING Indicates this session supports the set rating command.
long ACTION_SKIP_TO_NEXT Indicates this session supports the next command.
long ACTION_SKIP_TO_PREVIOUS Indicates this session supports the previous command.
long ACTION_SKIP_TO_QUEUE_ITEM Indicates this session supports the skip to queue item command.
long ACTION_STOP Indicates this session supports the stop command.
long PLAYBACK_POSITION_UNKNOWN Use this value for the position to indicate the position is not known.
int STATE_BUFFERING State indicating this item is currently buffering and will begin playing when enough data has buffered.
int STATE_ERROR State indicating this item is currently in an error state.
int STATE_FAST_FORWARDING State indicating this item is currently fast forwarding.
int STATE_NONE 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.
int STATE_PAUSED State indicating this item is currently paused.
int STATE_PLAYING State indicating this item is currently playing.
int STATE_REWINDING State indicating this item is currently rewinding.
int STATE_SKIPPING_TO_NEXT State indicating the player is currently skipping to the next item.
int STATE_SKIPPING_TO_PREVIOUS State indicating the player is currently skipping to the previous item.
int STATE_STOPPED State indicating this item is currently stopped.
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<PlaybackStateCompat> CREATOR
Public Methods
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
static PlaybackStateCompat fromPlaybackState(Object stateObj)
Creates an instance from a framework PlaybackState object.
long getActions()
Get the current actions available on this session.
long getBufferedPosition()
Get the current buffered position in ms.
CharSequence getErrorMessage()
Get a user readable error message.
long getLastPositionUpdateTime()
Get the elapsed real time at which position was last updated.
float getPlaybackSpeed()
Get the current playback speed as a multiple of normal playback.
Object getPlaybackState()
Gets the underlying framework PlaybackState object.
long getPosition()
Get the current playback position in ms.
int getState()
Get the current state of playback.
String toString()
Returns a string containing a concise, human-readable description of this object.
void writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final long ACTION_FAST_FORWARD

Indicates this session supports the fast forward command.

See Also
Constant Value: 64 (0x0000000000000040)

public static final long ACTION_PAUSE

Indicates this session supports the pause command.

See Also
Constant Value: 2 (0x0000000000000002)

public static final long ACTION_PLAY

Indicates this session supports the play command.

See Also
Constant Value: 4 (0x0000000000000004)

public static final long ACTION_PLAY_FROM_MEDIA_ID

Indicates this session supports the play from media id command.

See Also
Constant Value: 1024 (0x0000000000000400)

public static final long ACTION_PLAY_FROM_SEARCH

Indicates this session supports the play from search command.

See Also
Constant Value: 2048 (0x0000000000000800)

public static final long ACTION_PLAY_PAUSE

Indicates this session supports the play/pause toggle command.

See Also
Constant Value: 512 (0x0000000000000200)

public static final long ACTION_REWIND

Indicates this session supports the rewind command.

See Also
Constant Value: 8 (0x0000000000000008)

public static final long ACTION_SEEK_TO

Indicates this session supports the seek to command.

See Also
Constant Value: 256 (0x0000000000000100)

public static final long ACTION_SET_RATING

Indicates this session supports the set rating command.

See Also
Constant Value: 128 (0x0000000000000080)

public static final long ACTION_SKIP_TO_NEXT

Indicates this session supports the next command.

See Also
Constant Value: 32 (0x0000000000000020)

public static final long ACTION_SKIP_TO_PREVIOUS

Indicates this session supports the previous command.

See Also
Constant Value: 16 (0x0000000000000010)

public static final long ACTION_SKIP_TO_QUEUE_ITEM

Indicates this session supports the skip to queue item command.

See Also
Constant Value: 4096 (0x0000000000001000)

public static final long ACTION_STOP

Indicates this session supports the stop command.

See Also
Constant Value: 1 (0x0000000000000001)

public static final long PLAYBACK_POSITION_UNKNOWN

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

Constant Value: -1 (0xffffffffffffffff)

public static final int STATE_BUFFERING

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

Constant Value: 6 (0x00000006)

public static final int STATE_ERROR

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

Constant Value: 7 (0x00000007)

public static final int STATE_FAST_FORWARDING

State indicating this item is currently fast forwarding.

Constant Value: 4 (0x00000004)

public static final int STATE_NONE

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.

Constant Value: 0 (0x00000000)

public static final int STATE_PAUSED

State indicating this item is currently paused.

Constant Value: 2 (0x00000002)

public static final int STATE_PLAYING

State indicating this item is currently playing.

Constant Value: 3 (0x00000003)

public static final int STATE_REWINDING

State indicating this item is currently rewinding.

Constant Value: 5 (0x00000005)

public static final int STATE_SKIPPING_TO_NEXT

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

Constant Value: 10 (0x0000000a)

public static final int STATE_SKIPPING_TO_PREVIOUS

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

Constant Value: 9 (0x00000009)

public static final int STATE_STOPPED

State indicating this item is currently stopped.

Constant Value: 1 (0x00000001)

Fields

public static final Creator<PlaybackStateCompat> CREATOR

Public Methods

public int describeContents ()

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public static PlaybackStateCompat fromPlaybackState (Object stateObj)

Creates an instance from a framework PlaybackState object.

This method is only supported on API 21+.

Parameters
stateObj A PlaybackState object, or null if none.
Returns

public long getActions ()

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

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.

public CharSequence getErrorMessage ()

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

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
  • The last time the position was updated.

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
  • The current speed of playback.

public Object getPlaybackState ()

Gets the underlying framework PlaybackState object.

This method is only supported on API 21+.

Returns

public long getPosition ()

Get the current playback position in ms.

public int getState ()

public String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public void writeToParcel (Parcel dest, int flags)

Flatten this object in to a Parcel.

Parameters
dest The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.