Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

Builder

class Builder
kotlin.Any
   ↳ android.support.v4.media.session.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 methods

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

Add a custom action to the playback state.

PlaybackStateCompat.Builder!

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!)

Set a user readable error message.

PlaybackStateCompat.Builder!
setErrorMessage(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

<init>

Builder()

Create an empty Builder.

<init>

Builder(source: PlaybackStateCompat!)

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

Parameters
source PlaybackStateCompat!: The playback state to copy.

Public methods

addCustomAction

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 MediaControllerCompat.TransportControls#sendCustomAction(String, Bundle).
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 String!: The resource action of the icon that should be displayed for the action. The resource should be in the package of the MediaSessionCompat.
Return
PlaybackStateCompat.Builder!: this

addCustomAction

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.
Return
PlaybackStateCompat.Builder!: this

build

fun build(): PlaybackStateCompat!

Creates the playback state object.

setActiveQueueItemId

fun setActiveQueueItemId(id: Long): PlaybackStateCompat.Builder!

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

Parameters
id Long: The id of the active item.
Return
PlaybackStateCompat.Builder!: this

setBufferedPosition

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.

Return
PlaybackStateCompat.Builder!: this

setErrorMessage

fun setErrorMessage(errorMessage: CharSequence!): PlaybackStateCompat.Builder!

Deprecated: Use setErrorMessage(int, CharSequence) instead.

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

Return
PlaybackStateCompat.Builder!: this

setErrorMessage

fun setErrorMessage(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 PlaybackStateCompat#STATE_ERROR.

Parameters
errorCode Int: The errorCode to set.
errorMessage Int: The user readable error message. Can be null.
Return
PlaybackStateCompat.Builder!: this

setExtras

fun setExtras(extras: Bundle!): PlaybackStateCompat.Builder!

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

Parameters
extras Bundle!: The extras to include.
Return
PlaybackStateCompat.Builder!: this

setState

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 Int: The position in the current track in ms.
playbackSpeed Int: The current rate of playback as a multiple of normal playback.

setState

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 Int: The position in the current item in ms.
playbackSpeed Int: The current speed of playback as a multiple of normal playback.
updateTime Int: The time in the SystemClock#elapsedRealtime timebase that the position was updated at.
Return
PlaybackStateCompat.Builder!: this