FileDocCategorySizeDatePackage
PlaybackState.javaAPI DocAndroid 5.1 API34755Thu Mar 12 22:22:30 GMT 2015android.media.session

PlaybackState

public final class PlaybackState extends Object implements android.os.Parcelable
Playback state for a {@link MediaSession}. This includes a state like {@link PlaybackState#STATE_PLAYING}, the current playback position, and the current control capabilities.

Fields Summary
private static final String
TAG
public static final long
ACTION_STOP
Indicates this session supports the stop command.
public static final long
ACTION_PAUSE
Indicates this session supports the pause command.
public static final long
ACTION_PLAY
Indicates this session supports the play command.
public static final long
ACTION_REWIND
Indicates this session supports the rewind command.
public static final long
ACTION_SKIP_TO_PREVIOUS
Indicates this session supports the previous command.
public static final long
ACTION_SKIP_TO_NEXT
Indicates this session supports the next command.
public static final long
ACTION_FAST_FORWARD
Indicates this session supports the fast forward command.
public static final long
ACTION_SET_RATING
Indicates this session supports the set rating command.
public static final long
ACTION_SEEK_TO
Indicates this session supports the seek to command.
public static final long
ACTION_PLAY_PAUSE
Indicates this session supports the play/pause toggle command.
public static final long
ACTION_PLAY_FROM_MEDIA_ID
Indicates this session supports the play from media id command.
public static final long
ACTION_PLAY_FROM_SEARCH
Indicates this session supports the play from search command.
public static final long
ACTION_SKIP_TO_QUEUE_ITEM
Indicates this session supports the skip to queue item command.
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.
public static final int
STATE_STOPPED
State indicating this item is currently stopped.
public static final int
STATE_PAUSED
State indicating this item is currently paused.
public static final int
STATE_PLAYING
State indicating this item is currently playing.
public static final int
STATE_FAST_FORWARDING
State indicating this item is currently fast forwarding.
public static final int
STATE_REWINDING
State indicating this item is currently rewinding.
public static final int
STATE_BUFFERING
State indicating this item is currently buffering and will begin playing when enough data has buffered.
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.
public static final int
STATE_CONNECTING
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 {@link #STATE_NONE}. If the connection failed {@link #STATE_ERROR} should be used.
public static final int
STATE_SKIPPING_TO_PREVIOUS
State indicating the player is currently skipping to the previous item.
public static final int
STATE_SKIPPING_TO_NEXT
State indicating the player is currently skipping to the next item.
public static final int
STATE_SKIPPING_TO_QUEUE_ITEM
State indicating the player is currently skipping to a specific item in the queue.
public static final long
PLAYBACK_POSITION_UNKNOWN
Use this value for the position to indicate the position is not known.
private final int
mState
private final long
mPosition
private final long
mBufferedPosition
private final float
mSpeed
private final long
mActions
private List
mCustomActions
private final CharSequence
mErrorMessage
private final long
mUpdateTime
private final long
mActiveItemId
private final android.os.Bundle
mExtras
public static final Parcelable.Creator
CREATOR
Constructors Summary
private PlaybackState(int state, long position, long updateTime, float speed, long bufferedPosition, long transportControls, List customActions, long activeItemId, CharSequence error, android.os.Bundle extras)


            
               
               
                
        mState = state;
        mPosition = position;
        mSpeed = speed;
        mUpdateTime = updateTime;
        mBufferedPosition = bufferedPosition;
        mActions = transportControls;
        mCustomActions = new ArrayList<>(customActions);
        mActiveItemId = activeItemId;
        mErrorMessage = error;
        mExtras = extras;
    
private PlaybackState(android.os.Parcel in)

        mState = in.readInt();
        mPosition = in.readLong();
        mSpeed = in.readFloat();
        mUpdateTime = in.readLong();
        mBufferedPosition = in.readLong();
        mActions = in.readLong();
        mCustomActions = in.createTypedArrayList(CustomAction.CREATOR);
        mActiveItemId = in.readLong();
        mErrorMessage = in.readCharSequence();
        mExtras = in.readBundle();
    
Methods Summary
public intdescribeContents()

        return 0;
    
private static longgetActionForRccFlag(int flag)

        switch (flag) {
            case RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS:
                return ACTION_SKIP_TO_PREVIOUS;
            case RemoteControlClient.FLAG_KEY_MEDIA_REWIND:
                return ACTION_REWIND;
            case RemoteControlClient.FLAG_KEY_MEDIA_PLAY:
                return ACTION_PLAY;
            case RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE:
                return ACTION_PLAY_PAUSE;
            case RemoteControlClient.FLAG_KEY_MEDIA_PAUSE:
                return ACTION_PAUSE;
            case RemoteControlClient.FLAG_KEY_MEDIA_STOP:
                return ACTION_STOP;
            case RemoteControlClient.FLAG_KEY_MEDIA_FAST_FORWARD:
                return ACTION_FAST_FORWARD;
            case RemoteControlClient.FLAG_KEY_MEDIA_NEXT:
                return ACTION_SKIP_TO_NEXT;
            case RemoteControlClient.FLAG_KEY_MEDIA_POSITION_UPDATE:
                return ACTION_SEEK_TO;
            case RemoteControlClient.FLAG_KEY_MEDIA_RATING:
                return ACTION_SET_RATING;
        }
        return 0;
    
public longgetActions()
Get the current actions available on this session. This should use a bitmask of the available actions.
  • {@link PlaybackState#ACTION_SKIP_TO_PREVIOUS}
  • {@link PlaybackState#ACTION_REWIND}
  • {@link PlaybackState#ACTION_PLAY}
  • {@link PlaybackState#ACTION_PAUSE}
  • {@link PlaybackState#ACTION_STOP}
  • {@link PlaybackState#ACTION_FAST_FORWARD}
  • {@link PlaybackState#ACTION_SKIP_TO_NEXT}
  • {@link PlaybackState#ACTION_SEEK_TO}
  • {@link PlaybackState#ACTION_SET_RATING}

        return mActions;
    
public static longgetActionsFromRccControlFlags(int rccFlags)

hide

        long actions = 0;
        long flag = 1;
        while (flag <= rccFlags) {
            if ((flag & rccFlags) != 0) {
                actions |= getActionForRccFlag((int) flag);
            }
            flag = flag << 1;
        }
        return actions;
    
public longgetActiveQueueItemId()
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 {@link MediaSession.QueueItem#UNKNOWN_ID}.

return
The id of the currently active item in the queue or {@link MediaSession.QueueItem#UNKNOWN_ID}.

        return mActiveItemId;
    
public longgetBufferedPosition()
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.

        return mBufferedPosition;
    
public java.util.ListgetCustomActions()
Get the list of custom actions.

        return mCustomActions;
    
public java.lang.CharSequencegetErrorMessage()
Get a user readable error message. This should be set when the state is {@link PlaybackState#STATE_ERROR}.

        return mErrorMessage;
    
public android.os.BundlegetExtras()
Get any custom extras that were set on this playback state.

return
The extras for this state or null.

        return mExtras;
    
public longgetLastPositionUpdateTime()
Get the elapsed real time at which position was last updated. If the position has never been set this will return 0;

return
The last time the position was updated.

        return mUpdateTime;
    
public floatgetPlaybackSpeed()
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
The current speed of playback.

        return mSpeed;
    
public longgetPosition()
Get the current playback position in ms.

        return mPosition;
    
public static intgetRccControlFlagsFromActions(long actions)

hide

        int rccFlags = 0;
        long action = 1;
        while (action <= actions && action < Integer.MAX_VALUE) {
            if ((action & actions) != 0) {
                rccFlags |= getRccFlagForAction(action);
            }
            action = action << 1;
        }
        return rccFlags;
    
private static intgetRccFlagForAction(long action)

        // We only care about the lower set of actions that can map to rcc
        // flags.
        int testAction = action < Integer.MAX_VALUE ? (int) action : 0;
        switch (testAction) {
            case (int) ACTION_SKIP_TO_PREVIOUS:
                return RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS;
            case (int) ACTION_REWIND:
                return RemoteControlClient.FLAG_KEY_MEDIA_REWIND;
            case (int) ACTION_PLAY:
                return RemoteControlClient.FLAG_KEY_MEDIA_PLAY;
            case (int) ACTION_PLAY_PAUSE:
                return RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE;
            case (int) ACTION_PAUSE:
                return RemoteControlClient.FLAG_KEY_MEDIA_PAUSE;
            case (int) ACTION_STOP:
                return RemoteControlClient.FLAG_KEY_MEDIA_STOP;
            case (int) ACTION_FAST_FORWARD:
                return RemoteControlClient.FLAG_KEY_MEDIA_FAST_FORWARD;
            case (int) ACTION_SKIP_TO_NEXT:
                return RemoteControlClient.FLAG_KEY_MEDIA_NEXT;
            case (int) ACTION_SEEK_TO:
                return RemoteControlClient.FLAG_KEY_MEDIA_POSITION_UPDATE;
            case (int) ACTION_SET_RATING:
                return RemoteControlClient.FLAG_KEY_MEDIA_RATING;
        }
        return 0;
    
public static intgetRccStateFromState(int state)
Get the {@link RemoteControlClient} state for the given {@link PlaybackState} state.

param
state The state used by {@link PlaybackState}.
return
The equivalent state used by {@link RemoteControlClient}.
hide

        switch (state) {
            case STATE_BUFFERING:
                return RemoteControlClient.PLAYSTATE_BUFFERING;
            case STATE_ERROR:
                return RemoteControlClient.PLAYSTATE_ERROR;
            case STATE_FAST_FORWARDING:
                return RemoteControlClient.PLAYSTATE_FAST_FORWARDING;
            case STATE_NONE:
                return RemoteControlClient.PLAYSTATE_NONE;
            case STATE_PAUSED:
                return RemoteControlClient.PLAYSTATE_PAUSED;
            case STATE_PLAYING:
                return RemoteControlClient.PLAYSTATE_PLAYING;
            case STATE_REWINDING:
                return RemoteControlClient.PLAYSTATE_REWINDING;
            case STATE_SKIPPING_TO_PREVIOUS:
                return RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS;
            case STATE_SKIPPING_TO_NEXT:
                return RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS;
            case STATE_STOPPED:
                return RemoteControlClient.PLAYSTATE_STOPPED;
            default:
                return -1;
        }
    
public intgetState()
Get the current state of playback. One of the following:
  • {@link PlaybackState#STATE_NONE}
  • {@link PlaybackState#STATE_STOPPED}
  • {@link PlaybackState#STATE_PLAYING}
  • {@link PlaybackState#STATE_PAUSED}
  • {@link PlaybackState#STATE_FAST_FORWARDING}
  • {@link PlaybackState#STATE_REWINDING}
  • {@link PlaybackState#STATE_BUFFERING}
  • {@link PlaybackState#STATE_ERROR}

        return mState;
    
public static intgetStateFromRccState(int rccState)
Get the {@link PlaybackState} state for the given {@link RemoteControlClient} state.

param
rccState The state used by {@link RemoteControlClient}.
return
The equivalent state used by {@link PlaybackState}.
hide

        switch (rccState) {
            case RemoteControlClient.PLAYSTATE_BUFFERING:
                return STATE_BUFFERING;
            case RemoteControlClient.PLAYSTATE_ERROR:
                return STATE_ERROR;
            case RemoteControlClient.PLAYSTATE_FAST_FORWARDING:
                return STATE_FAST_FORWARDING;
            case RemoteControlClient.PLAYSTATE_NONE:
                return STATE_NONE;
            case RemoteControlClient.PLAYSTATE_PAUSED:
                return STATE_PAUSED;
            case RemoteControlClient.PLAYSTATE_PLAYING:
                return STATE_PLAYING;
            case RemoteControlClient.PLAYSTATE_REWINDING:
                return STATE_REWINDING;
            case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS:
                return STATE_SKIPPING_TO_PREVIOUS;
            case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS:
                return STATE_SKIPPING_TO_NEXT;
            case RemoteControlClient.PLAYSTATE_STOPPED:
                return STATE_STOPPED;
            default:
                return -1;
        }
    
public java.lang.StringtoString()

        StringBuilder bob = new StringBuilder("PlaybackState {");
        bob.append("state=").append(mState);
        bob.append(", position=").append(mPosition);
        bob.append(", buffered position=").append(mBufferedPosition);
        bob.append(", speed=").append(mSpeed);
        bob.append(", updated=").append(mUpdateTime);
        bob.append(", actions=").append(mActions);
        bob.append(", custom actions=").append(mCustomActions);
        bob.append(", active item id=").append(mActiveItemId);
        bob.append(", error=").append(mErrorMessage);
        bob.append("}");
        return bob.toString();
    
public voidwriteToParcel(android.os.Parcel dest, int flags)

        dest.writeInt(mState);
        dest.writeLong(mPosition);
        dest.writeFloat(mSpeed);
        dest.writeLong(mUpdateTime);
        dest.writeLong(mBufferedPosition);
        dest.writeLong(mActions);
        dest.writeTypedList(mCustomActions);
        dest.writeLong(mActiveItemId);
        dest.writeCharSequence(mErrorMessage);
        dest.writeBundle(mExtras);