Added in API level 21

Builder


class Builder
kotlin.Any
   ↳ android.media.session.PlaybackState.Builder

Builder for PlaybackState objects.

Summary

Public constructors

Creates an initially empty state builder.

Creates a builder with the same initial values as those in the from state.

Public methods
PlaybackState.Builder!
addCustomAction(action: String!, name: String!, icon: Int)

Add a custom action to the playback state.

PlaybackState.Builder!

Add a custom action to the playback state.

PlaybackState!

Build and return the PlaybackState instance with these values.

PlaybackState.Builder!
setActions(actions: Long)

Set the current actions available on this session.

PlaybackState.Builder!

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

PlaybackState.Builder!
setBufferedPosition(bufferedPosition: Long)

Set the current buffered position in ms.

PlaybackState.Builder!

Set a user readable error message.

PlaybackState.Builder!
setExtras(extras: Bundle!)

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

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

Set the current state of playback.

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

Set the current state of playback.

Public constructors

Builder

Added in API level 21
Builder()

Creates an initially empty state builder.

Builder

Added in API level 21
Builder(from: PlaybackState!)

Creates a builder with the same initial values as those in the from state.

Parameters
from PlaybackState!: The state to use for initializing the builder.

Public methods

addCustomAction

Added in API level 21
fun addCustomAction(
    action: String!,
    name: String!,
    icon: Int
): PlaybackState.Builder!

Add a custom action to the playback state. Actions can be used to expose additional functionality to MediaControllers 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 MediaSession through MediaController.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 Int: The resource action of the icon that should be displayed for the action. The resource should be in the package of the MediaSession.
Return
PlaybackState.Builder! this

addCustomAction

Added in API level 21
fun addCustomAction(customAction: PlaybackState.CustomAction!): PlaybackState.Builder!

Add a custom action to the playback state. Actions can be used to expose additional functionality to MediaControllers 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 PlaybackState.CustomAction!: The custom action to add to the PlaybackState.
Return
PlaybackState.Builder! this

build

Added in API level 21
fun build(): PlaybackState!

Build and return the PlaybackState instance with these values.

Return
PlaybackState! A new state instance.

setActions

Added in API level 21
fun setActions(actions: Long): PlaybackState.Builder!

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

Parameters
actions Long: The set of actions allowed. Value is either 0 or a combination of android.media.session.PlaybackState#ACTION_STOP, android.media.session.PlaybackState#ACTION_PAUSE, android.media.session.PlaybackState#ACTION_PLAY, android.media.session.PlaybackState#ACTION_REWIND, android.media.session.PlaybackState#ACTION_SKIP_TO_PREVIOUS, android.media.session.PlaybackState#ACTION_SKIP_TO_NEXT, android.media.session.PlaybackState#ACTION_FAST_FORWARD, android.media.session.PlaybackState#ACTION_SET_RATING, android.media.session.PlaybackState#ACTION_SEEK_TO, android.media.session.PlaybackState#ACTION_PLAY_PAUSE, android.media.session.PlaybackState#ACTION_PLAY_FROM_MEDIA_ID, android.media.session.PlaybackState#ACTION_PLAY_FROM_SEARCH, android.media.session.PlaybackState#ACTION_SKIP_TO_QUEUE_ITEM, android.media.session.PlaybackState#ACTION_PLAY_FROM_URI, android.media.session.PlaybackState#ACTION_PREPARE, android.media.session.PlaybackState#ACTION_PREPARE_FROM_MEDIA_ID, android.media.session.PlaybackState#ACTION_PREPARE_FROM_SEARCH, android.media.session.PlaybackState#ACTION_PREPARE_FROM_URI, and android.media.session.PlaybackState#ACTION_SET_PLAYBACK_SPEED
Return
PlaybackState.Builder! this

setActiveQueueItemId

Added in API level 21
fun setActiveQueueItemId(id: Long): PlaybackState.Builder!

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

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

setBufferedPosition

Added in API level 21
fun setBufferedPosition(bufferedPosition: Long): PlaybackState.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.

Parameters
bufferedPosition Long: The position in ms that playback is buffered to.
Return
PlaybackState.Builder! this

setErrorMessage

Added in API level 21
fun setErrorMessage(error: CharSequence!): PlaybackState.Builder!

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

Parameters
error CharSequence!: The error message for display to the user.
Return
PlaybackState.Builder! this

setExtras

Added in API level 22
fun setExtras(extras: Bundle!): PlaybackState.Builder!

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

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

setState

Added in API level 21
fun setState(
    state: Int,
    position: Long,
    playbackSpeed: Float,
    updateTime: Long
): PlaybackState.Builder!

Set the current state of playback.

The position must be in ms and indicates the current playback position within the item. If the position is unknown use PLAYBACK_POSITION_UNKNOWN. When not using an unknown position the time at which the position was updated must be provided. It is okay to use SystemClock#elapsedRealtime() if the current position was just retrieved.

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

The state must be one of the following:

Parameters
state Int: The current state of playback. Value is android.media.session.PlaybackState#STATE_NONE, android.media.session.PlaybackState#STATE_STOPPED, android.media.session.PlaybackState#STATE_PAUSED, android.media.session.PlaybackState#STATE_PLAYING, android.media.session.PlaybackState#STATE_FAST_FORWARDING, android.media.session.PlaybackState#STATE_REWINDING, android.media.session.PlaybackState#STATE_BUFFERING, android.media.session.PlaybackState#STATE_ERROR, android.media.session.PlaybackState#STATE_CONNECTING, android.media.session.PlaybackState#STATE_SKIPPING_TO_PREVIOUS, android.media.session.PlaybackState#STATE_SKIPPING_TO_NEXT, android.media.session.PlaybackState#STATE_SKIPPING_TO_QUEUE_ITEM, or android.media.session.PlaybackState.STATE_PLAYBACK_SUPPRESSED
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 SystemClock#elapsedRealtime timebase that the position was updated at.
Return
PlaybackState.Builder! this

setState

Added in API level 21
fun setState(
    state: Int,
    position: Long,
    playbackSpeed: Float
): PlaybackState.Builder!

Set the current state of playback.

The position must be in ms and indicates the current playback position within the item. If the position is unknown use PLAYBACK_POSITION_UNKNOWN. The update time will be set to the current SystemClock#elapsedRealtime().

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

The state must be one of the following:

Parameters
state Int: The current state of playback. Value is android.media.session.PlaybackState#STATE_NONE, android.media.session.PlaybackState#STATE_STOPPED, android.media.session.PlaybackState#STATE_PAUSED, android.media.session.PlaybackState#STATE_PLAYING, android.media.session.PlaybackState#STATE_FAST_FORWARDING, android.media.session.PlaybackState#STATE_REWINDING, android.media.session.PlaybackState#STATE_BUFFERING, android.media.session.PlaybackState#STATE_ERROR, android.media.session.PlaybackState#STATE_CONNECTING, android.media.session.PlaybackState#STATE_SKIPPING_TO_PREVIOUS, android.media.session.PlaybackState#STATE_SKIPPING_TO_NEXT, android.media.session.PlaybackState#STATE_SKIPPING_TO_QUEUE_ITEM, or android.media.session.PlaybackState.STATE_PLAYBACK_SUPPRESSED
position Long: The position in the current item in ms.
playbackSpeed Float: The current speed of playback as a multiple of normal playback.
Return
PlaybackState.Builder! this