ProgressStateWithTickInterval

@UnstableApi
class ProgressStateWithTickInterval


State that holds playback progress information of a Player. This includes playback position, buffered position and duration.

This class is optimised for state changes according to the media clock. A composable UI element that makes use of such androidx.compose.runtime.MutableState elements will recompose at the frequency of those updates, leading to a more efficient performance.

For example, for a textual-based UI, the current position usually requires "ticking" on the second, on the minute or some other step definition according to the media clock rather than elapsed real time. The coarseness of the interval can be carefully chosen as the granularity of the displayed string.

In most cases, this will be created via rememberProgressStateWithTickInterval.

Summary

Public constructors

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

Public functions

suspend Nothing

Subscribes to updates from Player.Events to track changes of progress-related information in an asynchronous way.

Public properties

Long

An estimate of the position in the current content or ad up to which data is buffered, in milliseconds.

Long

The playback position in the current content or ad, in milliseconds, matches Player.getCurrentPosition that is rounded to a multiple of tickIntervalMs.

Long

The duration of the current content or ad in milliseconds, matches Player.getDuration.

Public constructors

ProgressStateWithTickInterval

ProgressStateWithTickInterval(
    player: Player,
    tickIntervalMs: @IntRange(from = 0) Long = 0,
    scope: CoroutineScope
)
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/tick, in milliseconds. A value of 0 indicates continuous updates, coming at the rate of Compose runtime requesting new frames. The 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

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.

Public functions

observe

suspend fun observe(): Nothing

Subscribes to updates from Player.Events to track changes of progress-related information in an asynchronous way.

Public properties

bufferedPositionMs

val bufferedPositionMsLong

An estimate of the position in the current content or ad up to which data is buffered, in milliseconds.

currentPositionMs

val currentPositionMsLong

The playback position in the current content or ad, in milliseconds, matches Player.getCurrentPosition that is rounded to a multiple of tickIntervalMs.

durationMs

val durationMsLong

The duration of the current content or ad in milliseconds, matches Player.getDuration.