PlaybackStateCompat.Builder

class PlaybackStateCompat.Builder


Builder for PlaybackStateCompat objects.

Summary

Public constructors

Create an empty Builder.

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

Public functions

PlaybackStateCompat.Builder!

Add a custom action to the playback state.

PlaybackStateCompat.Builder!
addCustomAction(action: String!, name: String!, icon: Int)

Add a custom action to the playback state.

PlaybackStateCompat!

Creates the playback state object.

PlaybackStateCompat.Builder!
setActions(capabilities: Long)

Set the current capabilities available on this session.

PlaybackStateCompat.Builder!

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

PlaybackStateCompat.Builder!
setBufferedPosition(bufferPosition: Long)

Set the current buffered position in ms.

PlaybackStateCompat.Builder!
setErrorMessage(errorMessage: CharSequence!)

This function is deprecated.

Use setErrorMessage instead.

PlaybackStateCompat.Builder!
setErrorMessage(
    @PlaybackStateCompat.ErrorCode errorCode: Int,
    errorMessage: CharSequence!
)

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

PlaybackStateCompat.Builder!
setExtras(extras: Bundle!)

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

PlaybackStateCompat.Builder!
setState(state: Int, position: Long, playbackSpeed: Float)

Set the current state of playback.

PlaybackStateCompat.Builder!
setState(state: Int, position: Long, playbackSpeed: Float, updateTime: Long)

Set the current state of playback.

Public constructors

Builder

Added in 1.1.0
Builder()

Create an empty Builder.

Builder

Added in 1.1.0
Builder(source: PlaybackStateCompat!)

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

Parameters
source: PlaybackStateCompat!

The playback state to copy.

Public functions

addCustomAction

Added in 1.1.0
fun addCustomAction(customAction: PlaybackStateCompat.CustomAction!): PlaybackStateCompat.Builder!

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: PlaybackStateCompat.CustomAction!

The custom action to add to the PlaybackStateCompat.

addCustomAction

Added in 1.1.0
fun addCustomAction(action: String!, name: String!, icon: Int): PlaybackStateCompat.Builder!

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: String!

An identifier for this action. It can be sent back to the MediaSessionCompat through sendCustomAction.

name: String!

The display name for the action. If text is shown with the action or used for accessibility, this is what should be used.

icon: Int

The resource action of the icon that should be displayed for the action. The resource should be in the package of the MediaSessionCompat.

build

Added in 1.1.0
fun build(): PlaybackStateCompat!

Creates the playback state object.

setActiveQueueItemId

Added in 1.1.0
fun setActiveQueueItemId(id: Long): PlaybackStateCompat.Builder!

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

Parameters
id: Long

The id of the active item.

setBufferedPosition

Added in 1.1.0
fun setBufferedPosition(bufferPosition: Long): PlaybackStateCompat.Builder!

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.

setErrorMessage

Added in 1.1.0
Deprecated in 1.1.0
fun setErrorMessage(errorMessage: CharSequence!): PlaybackStateCompat.Builder!

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

setErrorMessage

Added in 1.1.0
fun setErrorMessage(
    @PlaybackStateCompat.ErrorCode errorCode: Int,
    errorMessage: CharSequence!
): PlaybackStateCompat.Builder!

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

Parameters
@PlaybackStateCompat.ErrorCode errorCode: Int

The errorCode to set.

errorMessage: CharSequence!

The user readable error message. Can be null.

setExtras

Added in 1.1.0
fun setExtras(extras: Bundle!): PlaybackStateCompat.Builder!

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

Parameters
extras: Bundle!

The extras to include.

setState

Added in 1.1.0
fun setState(state: Int, position: Long, playbackSpeed: Float): PlaybackStateCompat.Builder!

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 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: Int

The current state of playback.

position: Long

The position in the current track in ms.

playbackSpeed: Float

The current rate of playback as a multiple of normal playback.

setState

Added in 1.1.0
fun setState(state: Int, position: Long, playbackSpeed: Float, updateTime: Long): PlaybackStateCompat.Builder!

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 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: Int

The current state of playback.

position: Long

The position in the current item in ms.

playbackSpeed: Float

The current speed of playback as a multiple of normal playback.

updateTime: Long

The time in the elapsedRealtime timebase that the position was updated at.