FileDocCategorySizeDatePackage
PlaybackStateCompat.javaAPI DocAndroid 5.1 API25058Thu Mar 12 22:22:56 GMT 2015android.support.v4.media.session

PlaybackStateCompat

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

Fields Summary
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 route. 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 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 final CharSequence
mErrorMessage
private final long
mUpdateTime
private Object
mStateObj
public static final Parcelable.Creator
CREATOR
Constructors Summary
private PlaybackStateCompat(int state, long position, long bufferedPosition, float rate, long actions, CharSequence errorMessage, long updateTime)


          
                    
        mState = state;
        mPosition = position;
        mBufferedPosition = bufferedPosition;
        mSpeed = rate;
        mActions = actions;
        mErrorMessage = errorMessage;
        mUpdateTime = updateTime;
    
private PlaybackStateCompat(android.os.Parcel in)

        mState = in.readInt();
        mPosition = in.readLong();
        mSpeed = in.readFloat();
        mUpdateTime = in.readLong();
        mBufferedPosition = in.readLong();
        mActions = in.readLong();
        mErrorMessage = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
    
Methods Summary
public intdescribeContents()

        return 0;
    
public static android.support.v4.media.session.PlaybackStateCompatfromPlaybackState(java.lang.Object stateObj)
Creates an instance from a framework {@link android.media.session.PlaybackState} object.

This method is only supported on API 21+.

param
stateObj A {@link android.media.session.PlaybackState} object, or null if none.
return
An equivalent {@link PlaybackStateCompat} object, or null if none.

        if (stateObj == null || Build.VERSION.SDK_INT < 21) {
            return null;
        }

        PlaybackStateCompat state = new PlaybackStateCompat(
                PlaybackStateCompatApi21.getState(stateObj),
                PlaybackStateCompatApi21.getPosition(stateObj),
                PlaybackStateCompatApi21.getBufferedPosition(stateObj),
                PlaybackStateCompatApi21.getPlaybackSpeed(stateObj),
                PlaybackStateCompatApi21.getActions(stateObj),
                PlaybackStateCompatApi21.getErrorMessage(stateObj),
                PlaybackStateCompatApi21.getLastPositionUpdateTime(stateObj));
        state.mStateObj = stateObj;
        return state;
    
public longgetActions()
Get the current actions available on this session. This should use a bitmask of the available actions.
  • {@link PlaybackStateCompat#ACTION_SKIP_TO_PREVIOUS}
  • {@link PlaybackStateCompat#ACTION_REWIND}
  • {@link PlaybackStateCompat#ACTION_PLAY}
  • {@link PlaybackStateCompat#ACTION_PAUSE}
  • {@link PlaybackStateCompat#ACTION_STOP}
  • {@link PlaybackStateCompat#ACTION_FAST_FORWARD}
  • {@link PlaybackStateCompat#ACTION_SKIP_TO_NEXT}
  • {@link PlaybackStateCompat#ACTION_SEEK_TO}
  • {@link PlaybackStateCompat#ACTION_SET_RATING}

        return mActions;
    
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.lang.CharSequencegetErrorMessage()
Get a user readable error message. This should be set when the state is {@link PlaybackStateCompat#STATE_ERROR}.

        return mErrorMessage;
    
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 java.lang.ObjectgetPlaybackState()
Gets the underlying framework {@link android.media.session.PlaybackState} object.

This method is only supported on API 21+.

return
An equivalent {@link android.media.session.PlaybackState} object, or null if none.

        if (mStateObj != null || Build.VERSION.SDK_INT < 21) {
            return mStateObj;
        }

        mStateObj = PlaybackStateCompatApi21.newInstance(mState, mPosition, mBufferedPosition,
                mSpeed, mActions, mErrorMessage, mUpdateTime);
        return mStateObj;
    
public longgetPosition()
Get the current playback position in ms.

        return mPosition;
    
public intgetState()
Get the current state of playback. One of the following:
  • {@link PlaybackStateCompat#STATE_NONE}
  • {@link PlaybackStateCompat#STATE_STOPPED}
  • {@link PlaybackStateCompat#STATE_PLAYING}
  • {@link PlaybackStateCompat#STATE_PAUSED}
  • {@link PlaybackStateCompat#STATE_FAST_FORWARDING}
  • {@link PlaybackStateCompat#STATE_REWINDING}
  • {@link PlaybackStateCompat#STATE_BUFFERING}
  • {@link PlaybackStateCompat#STATE_ERROR}
  •         return mState;
        
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(", 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);
        TextUtils.writeToParcel(mErrorMessage, dest, flags);