PlaybackSpeedState

@UnstableApi
class PlaybackSpeedState


State that holds all interactions to correctly deal with a UI component representing a playback speed controller.

In most cases, this will be created via rememberPlaybackSpeedState.

Summary

Public constructors

Public functions

suspend Unit

Subscribes to updates from Player.Events and listens to

Unit

Restores the playback speed to the value it had before the first call to temporarilyOverrideSpeedWith.

Unit

Starts a temporary speed override, i.e. fast-forward or slow motion.

Unit

Updates the playback speed of the Player backing this state.

Public properties

Boolean

true if player is not null and Player.COMMAND_SET_SPEED_AND_PITCH is available.

Float

determined by Player.playbackParameters.speed.

Public constructors

PlaybackSpeedState

PlaybackSpeedState(player: Player?)
Parameters
player: Player?

Player object that operates as a state provider.

Public functions

observe

suspend fun observe(): Unit

Subscribes to updates from Player.Events and listens to

restoreOverriddenSpeed

fun restoreOverriddenSpeed(): Unit

Restores the playback speed to the value it had before the first call to temporarilyOverrideSpeedWith.

If the playback speed is changed while a temporary override is active, this method will still restore the speed to the value that was current before the override began.

temporarilyOverrideSpeedWith

fun temporarilyOverrideSpeedWith(speed: Float): Unit

Starts a temporary speed override, i.e. fast-forward or slow motion.

If there isn't an ongoing override, remembers the current speed to restore later.

updatePlaybackSpeed

fun updatePlaybackSpeed(speed: Float): Unit

Updates the playback speed of the Player backing this state.

This method does nothing if Player.COMMAND_SET_SPEED_AND_PITCH is not available.

Public properties

isEnabled

val isEnabledBoolean

true if player is not null and Player.COMMAND_SET_SPEED_AND_PITCH is available.

playbackSpeed

val playbackSpeedFloat

determined by Player.playbackParameters.speed. Defaults to 1f if the player is null.