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.

Unit

Seeks to the default position associated with the current media item.

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.

Boolean

Whether the currently playing item is a live stream.

Long

The offset of the current playback position from the live edge in milliseconds, or C.TIME_UNSET if the current media item isn't live or the offset is unknown.

Long

The duration of the current media item in milliseconds before any clipping of its start or end.

Boolean

Whether seeking to the default position is enabled, i.e., Player.COMMAND_SEEK_TO_DEFAULT_POSITION is available.

Long

The target live offset in milliseconds if configured.

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.

seekToDefaultPosition

fun seekToDefaultPosition(): Unit

Seeks to the default position associated with the current media item. For live streams, this will typically be the live edge.

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

Public properties

bufferedPositionMs

val bufferedPositionMs: Long

An estimate of the position in the current content or ad up to which data is buffered, in milliseconds. Smoothed for live streams in the same way as currentPositionMs.

currentPositionMs

val currentPositionMs: Long

The playback position in the current content or ad, in milliseconds, matches Player.getCurrentPosition that is rounded to a multiple of tickIntervalMs. For live streams with a sliding window, the position is relative to a smoothly advancing window start, so that it does not jump whenever the live window is updated.

durationMs

val durationMs: Long

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

isLive

val isLive: Boolean

Whether the currently playing item is a live stream. Always false while an ad is playing.

liveOffsetMs

val liveOffsetMs: Long

The offset of the current playback position from the live edge in milliseconds, or C.TIME_UNSET if the current media item isn't live or the offset is unknown.

originalDurationMs

val originalDurationMs: Long

The duration of the current media item in milliseconds before any clipping of its start or end. Equal to durationMs if the media item isn't clipped, its original duration isn't known, it has multiple periods, or an ad is playing.

seekToDefaultPositionEnabled

val seekToDefaultPositionEnabled: Boolean

Whether seeking to the default position is enabled, i.e., Player.COMMAND_SEEK_TO_DEFAULT_POSITION is available.

targetLiveOffsetMs

val targetLiveOffsetMs: Long

The target live offset in milliseconds if configured. Otherwise, the offset of the default position, measured in the same way as liveOffsetMs if the window start time is known, or from the end of the window if not. C.TIME_UNSET if unknown or not a live stream.