androidx.media3.ui.compose.state

Classes

MuteButtonState

State that holds all interactions to correctly deal with a UI component representing a Mute button.

NextButtonState

State that holds all interactions to correctly deal with a UI component representing a seek-to-next button.

PlayPauseButtonState

State that converts the necessary information from the Player to correctly deal with a UI component representing a PlayPause button.

PlaybackSpeedState

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

PresentationState

State that holds information to correctly deal with UI components related to the rendering of frames to a surface.

PreviousButtonState

State that holds all interactions to correctly deal with a UI component representing a seek-to-previous button.

ProgressStateWithTickCount

State that aims to hold accurate progress information (position, bufferedPosition, duration) that is required for a UI component representing a non-textual progress indicator, e.g. circular or linear.

ProgressStateWithTickInterval

State that holds playback progress information of a Player.

RepeatButtonState

State that holds all interactions to correctly deal with a UI component representing a Repeat On/All/Off button.

SeekBackButtonState

State that holds all interactions to correctly deal with a UI component representing a seek back button.

SeekForwardButtonState

State that holds all interactions to correctly deal with a UI component representing a seek forward button.

ShuffleButtonState

State that holds all interactions to correctly deal with a UI component representing a Shuffle On/Off button.

Constants summary

Top-level functions summary

MuteButtonState

Remembers the value of MuteButtonState created based on the passed Player and launch a coroutine to listen to Player's changes.

NextButtonState

Remembers the value of NextButtonState created based on the passed Player and launch a coroutine to listen to Player's changes.

PlayPauseButtonState

Remembers the value of PlayPauseButtonState created based on the passed Player and launch a coroutine to listen to Player's changes.

PlaybackSpeedState

Remember the value of PlaybackSpeedState created based on the passed Player and launch a coroutine to listen to Player's changes.

PresentationState

Remembers the value of PresentationState created based on the passed Player and launches a coroutine to listen to Player's changes.

PreviousButtonState

Remembers the value of PreviousButtonState created based on the passed Player and launch a coroutine to listen to Player's changes.

ProgressStateWithTickCount
@UnstableApi
@Composable
rememberProgressStateWithTickCount(
    player: Player,
    totalTickCount: @IntRange(from = 0) Int,
    scope: CoroutineScope
)

Remember the value of ProgressStateWithTickCount created based on the passed Player and launch a coroutine to listen to Player's changes.

ProgressStateWithTickInterval
@UnstableApi
@Composable
rememberProgressStateWithTickInterval(
    player: Player,
    tickIntervalMs: @IntRange(from = 0) Long,
    scope: CoroutineScope
)

Remember the value of ProgressStateWithTickInterval created based on the passed Player and launch a coroutine to listen to Player's changes.

RepeatButtonState
@UnstableApi
@Composable
rememberRepeatButtonState(
    player: Player,
    toggleModeSequence: List<@Player.RepeatMode Int>
)

Remember the value of RepeatButtonState created based on the passed Player and launch a coroutine to listen to Player's changes.

SeekBackButtonState

Remembers the value of SeekBackButtonState created based on the passed Player and launch a coroutine to listen to Player's changes.

SeekForwardButtonState

Remembers the value of SeekForwardButtonState created based on the passed Player and launch a coroutine to listen to Player's changes.

ShuffleButtonState

Remember the value of ShuffleButtonState created based on the passed Player and launch a coroutine to listen to Player's changes.

Constants

FALLBACK_UPDATE_INTERVAL_MS

@VisibleForTesting(otherwise = 2)
const val FALLBACK_UPDATE_INTERVAL_MS = 1000: Long

MIN_UPDATE_INTERVAL_MS

@UnstableApi
const val MIN_UPDATE_INTERVAL_MS = 8: Long

Top-level functions

rememberMuteButtonState

@UnstableApi
@Composable
fun rememberMuteButtonState(player: Player): MuteButtonState

Remembers the value of MuteButtonState created based on the passed Player and launch a coroutine to listen to Player's changes. If the Player instance changes between compositions, produce and remember a new value.

rememberNextButtonState

@UnstableApi
@Composable
fun rememberNextButtonState(player: Player): NextButtonState

Remembers the value of NextButtonState created based on the passed Player and launch a coroutine to listen to Player's changes. If the Player instance changes between compositions, produce and remember a new value.

rememberPlayPauseButtonState

@UnstableApi
@Composable
fun rememberPlayPauseButtonState(player: Player): PlayPauseButtonState

Remembers the value of PlayPauseButtonState created based on the passed Player and launch a coroutine to listen to Player's changes. If the Player instance changes between compositions, produce and remember a new value.

rememberPlaybackSpeedState

@UnstableApi
@Composable
fun rememberPlaybackSpeedState(player: Player): PlaybackSpeedState

Remember the value of PlaybackSpeedState created based on the passed Player and launch a coroutine to listen to Player's changes. If the Player instance changes between compositions, produce and remember a new value.

rememberPresentationState

@UnstableApi
@Composable
fun rememberPresentationState(
    player: Player?,
    keepContentOnReset: Boolean = false
): PresentationState

Remembers the value of PresentationState created based on the passed Player and launches a coroutine to listen to Player's changes.

Note that if the Player instance changes between compositions, the method will not produce a new value. The same object will be reused and subscribe to the Player.Events of the new player.

Parameters
player: Player?

the Player whose PresentationState will be controlled.

keepContentOnReset: Boolean = false

whether the currently displayed video frame or media artwork is kept visible when tracks change or player changes. Defaults to false.

rememberPreviousButtonState

@UnstableApi
@Composable
fun rememberPreviousButtonState(player: Player): PreviousButtonState

Remembers the value of PreviousButtonState created based on the passed Player and launch a coroutine to listen to Player's changes. If the Player instance changes between compositions, produce and remember a new value.

rememberProgressStateWithTickCount

@UnstableApi
@Composable
fun rememberProgressStateWithTickCount(
    player: Player,
    totalTickCount: @IntRange(from = 0) Int = 0,
    scope: CoroutineScope = rememberCoroutineScope()
): ProgressStateWithTickCount

Remember the value of ProgressStateWithTickCount created based on the passed Player and launch a coroutine to listen to Player's changes. If the Player instance changes between compositions, produce and remember a new value.

ProgressStateWithTickCount is a state holder optimised for updates according to the discrete number of ticks that make up the full progress. Non-textual UI components are limited in how much progress they can show by their screen representation, such as the number of pixels. In this case, it is more important to track progress in ticks/steps that correspond to a visible "jump" rather than a particular real time or media time frequency. Make sure to tune the totalTickCount value for the shape of the composable that is consuming this state. This will help you keep the recomposition count low, since the updates will be triggered at the frequency that matches the needs of the UI.

Parameters
player: Player

The player whose progress to observe.

totalTickCount: @IntRange(from = 0) Int = 0

If strictly greater than 0, specifies the amounts of discrete values, evenly distributed across the whole duration of the current media item. If 0, ProgressStateWithTickCount.currentPositionProgress and ProgressStateWithTickCount.bufferedPositionProgress will remain 0 until this value becomes positive. Must not be negative.

scope: CoroutineScope = rememberCoroutineScope()

Coroutine scope whose context is used to launch the progress update job. When scoped to some UI element, the scope of the Composable will ensure the job is cancelled when the element is disposed.

Returns
ProgressStateWithTickCount

The remembered ProgressStateWithTickCount instance.

rememberProgressStateWithTickInterval

@UnstableApi
@Composable
fun rememberProgressStateWithTickInterval(
    player: Player,
    tickIntervalMs: @IntRange(from = 0) Long = 0,
    scope: CoroutineScope = rememberCoroutineScope()
): ProgressStateWithTickInterval

Remember the value of ProgressStateWithTickInterval created based on the passed Player and launch a coroutine to listen to Player's changes. If the Player instance changes between compositions, produce and remember a new value.

ProgressStateWithTickInterval is a state holder optimised for updates according to the media clock at the provided tickIntervalMs interval. Make sure to tune the interval value for the shape of the composable that is consuming this state.

Parameters
player: Player

The player whose progress to observe.

tickIntervalMs: @IntRange(from = 0) Long = 0

Delta of the media time that constitutes a progress step, in milliseconds. A value of 0 indicates continuous updates, coming at the rate of Compose runtime requesting new frames. The ProgressStateWithTickInterval.currentPositionMs will aim to be updated at the tickIntervalMs interval. The updates might sometimes be more frequent, or less frequent for small values of tickIntervalMs (where the screen is refreshing less frequently).

scope: CoroutineScope = rememberCoroutineScope()

Coroutine scope whose context is used to launch the progress update job. When scoped to some UI element, the scope of the Composable will ensure the job is cancelled when the element is disposed.

rememberRepeatButtonState

@UnstableApi
@Composable
fun rememberRepeatButtonState(
    player: Player,
    toggleModeSequence: List<@Player.RepeatMode Int> = listOf(Player.REPEAT_MODE_OFF, Player.REPEAT_MODE_ONE, Player.REPEAT_MODE_ALL)
): RepeatButtonState

Remember the value of RepeatButtonState created based on the passed Player and launch a coroutine to listen to Player's changes. If the Player instance changes between compositions, produce and remember a new value.

rememberSeekBackButtonState

@UnstableApi
@Composable
fun rememberSeekBackButtonState(player: Player): SeekBackButtonState

Remembers the value of SeekBackButtonState created based on the passed Player and launch a coroutine to listen to Player's changes. If the Player instance changes between compositions, produce and remember a new value.

rememberSeekForwardButtonState

@UnstableApi
@Composable
fun rememberSeekForwardButtonState(player: Player): SeekForwardButtonState

Remembers the value of SeekForwardButtonState created based on the passed Player and launch a coroutine to listen to Player's changes. If the Player instance changes between compositions, produce and remember a new value.

rememberShuffleButtonState

@UnstableApi
@Composable
fun rememberShuffleButtonState(player: Player): ShuffleButtonState

Remember the value of ShuffleButtonState created based on the passed Player and launch a coroutine to listen to Player's changes. If the Player instance changes between compositions, produce and remember a new value.