public final class

PlaybackStateCompat.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.media3.session.legacy.PlaybackStateCompat.Builder

Overview

Builder for PlaybackStateCompat objects.

Summary

Constructors
publicBuilder()

Create an empty Builder.

publicBuilder(PlaybackStateCompat source)

Create a Builder using a PlaybackStateCompat instance to set the initial values.

Methods
public PlaybackStateCompat.BuilderaddCustomAction(PlaybackStateCompat.CustomAction customAction)

Add a custom action to the playback state.

public PlaybackStateCompat.BuilderaddCustomAction(java.lang.String action, java.lang.String name, int icon)

Add a custom action to the playback state.

public PlaybackStateCompatbuild()

Creates the playback state object.

public PlaybackStateCompat.BuildersetActions(long capabilities)

Set the current capabilities available on this session.

public PlaybackStateCompat.BuildersetActiveQueueItemId(long id)

Set the active item in the play queue by specifying its id.

public PlaybackStateCompat.BuildersetBufferedPosition(long bufferPosition)

Set the current buffered position in ms.

public PlaybackStateCompat.BuildersetErrorMessage(java.lang.CharSequence errorMessage)

Set a user readable error message.

public PlaybackStateCompat.BuildersetErrorMessage(int errorCode, java.lang.CharSequence errorMessage)

Set the error code with an optional user readable error message.

public PlaybackStateCompat.BuildersetExtras(Bundle extras)

Set any custom extras to be included with the playback state.

public PlaybackStateCompat.BuildersetState(int state, long position, float playbackSpeed)

Set the current state of playback.

public PlaybackStateCompat.BuildersetState(int state, long position, float playbackSpeed, long updateTime)

Set the current state of playback.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Create an empty Builder.

public Builder(PlaybackStateCompat source)

Create a Builder using a PlaybackStateCompat instance to set the initial values.

Parameters:

source: The playback state to copy.

Methods

public PlaybackStateCompat.Builder setState(int state, long position, float playbackSpeed)

Set the current state of playback.

The position must be in ms and indicates the current playback position within the track. If the position is unknown use PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN.

The rate is a multiple of normal playback and should be 0 when paused and negative when rewinding. Normal playback rate is 1.0.

The state must be one of the following:

Parameters:

state: The current state of playback.
position: The position in the current track in ms.
playbackSpeed: The current rate of playback as a multiple of normal playback.

public PlaybackStateCompat.Builder setState(int state, long position, float playbackSpeed, long updateTime)

Set the current state of playback.

The position must be in ms and indicates the current playback position within the track. If the position is unknown use PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN.

The rate is a multiple of normal playback and should be 0 when paused and negative when rewinding. Normal playback rate is 1.0.

The state must be one of the following:

Parameters:

state: The current state of playback.
position: The position in the current item in ms.
playbackSpeed: The current speed of playback as a multiple of normal playback.
updateTime: The time in the timebase that the position was updated at.

Returns:

this

public PlaybackStateCompat.Builder setBufferedPosition(long bufferPosition)

Set the current buffered position in ms. This is the farthest playback point that can be reached from the current position using only buffered content.

Returns:

this

public PlaybackStateCompat.Builder setActions(long capabilities)

Set the current capabilities available on this session. This should use a bitmask of the available capabilities.

Returns:

this

public PlaybackStateCompat.Builder addCustomAction(java.lang.String action, java.lang.String name, int icon)

Add a custom action to the playback state. Actions can be used to expose additional functionality to Controllers beyond what is offered by the standard transport controls.

e.g. start a radio station based on the current item or skip ahead by 30 seconds.

Parameters:

action: An identifier for this action. It can be sent back to the MediaSessionCompat through MediaControllerCompat.TransportControls.sendCustomAction(String, Bundle).
name: The display name for the action. If text is shown with the action or used for accessibility, this is what should be used.
icon: The resource action of the icon that should be displayed for the action. The resource should be in the package of the MediaSessionCompat.

Returns:

this

Add a custom action to the playback state. Actions can be used to expose additional functionality to Controllers beyond what is offered by the standard transport controls.

An example of an action would be to start a radio station based on the current item or to skip ahead by 30 seconds.

Parameters:

customAction: The custom action to add to the PlaybackStateCompat.

Returns:

this

public PlaybackStateCompat.Builder setActiveQueueItemId(long id)

Set the active item in the play queue by specifying its id. The default value is MediaSessionCompat.QueueItem.UNKNOWN_ID

Parameters:

id: The id of the active item.

Returns:

this

public PlaybackStateCompat.Builder setErrorMessage(java.lang.CharSequence errorMessage)

Deprecated: Use PlaybackStateCompat.Builder.setErrorMessage(int, CharSequence) instead.

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

Returns:

this

public PlaybackStateCompat.Builder setErrorMessage(int errorCode, java.lang.CharSequence errorMessage)

Set the error code with an optional user readable error message. This should be set when the state is PlaybackStateCompat.STATE_ERROR.

Parameters:

errorCode: The errorCode to set.
errorMessage: The user readable error message. Can be null.

Returns:

this

public PlaybackStateCompat.Builder setExtras(Bundle extras)

Set any custom extras to be included with the playback state.

Parameters:

extras: The extras to include.

Returns:

this

public PlaybackStateCompat build()

Creates the playback state object.