CurrentMediaItemState

@UnstableApi
class CurrentMediaItemState


A state holder that observes a Player and provides reactive updates for properties of the currently playing media item.

This state includes both static configuration from the MediaItem and dynamic information obtained from the player's androidx.media3.common.Timeline and MediaMetadata.

Use rememberCurrentMediaItemState to create and manage the lifecycle of this state within a Composable.

Summary

Public constructors

Public functions

suspend Unit

Public properties

Long

The duration of the currently playing item (content or ad) in milliseconds, or C.TIME_UNSET if the duration is unknown or the command is not available.

Boolean

Whether the player is currently playing an ad.

Boolean

Whether the currently playing item is a live stream.

MediaItem?

The currently playing MediaItem, or null if no item is being played or the Player.COMMAND_GET_CURRENT_MEDIA_ITEM is not available.

MediaMetadata

The combined MediaMetadata for the current item, including both static metadata from the MediaItem and dynamic updates from the stream.

Public constructors

CurrentMediaItemState

CurrentMediaItemState(player: Player?)

Public functions

observe

suspend fun observe(): Unit

Public properties

durationMs

val durationMsLong

The duration of the currently playing item (content or ad) in milliseconds, or C.TIME_UNSET if the duration is unknown or the command is not available.

isAd

val isAdBoolean

Whether the player is currently playing an ad. When true, properties like durationMs will reflect the duration of the current ad rather than the main content.

isLive

val isLiveBoolean

Whether the currently playing item is a live stream.

mediaItem

val mediaItemMediaItem?

The currently playing MediaItem, or null if no item is being played or the Player.COMMAND_GET_CURRENT_MEDIA_ITEM is not available.

mediaMetadata

val mediaMetadataMediaMetadata

The combined MediaMetadata for the current item, including both static metadata from the MediaItem and dynamic updates from the stream. Returns MediaMetadata.EMPTY if metadata is not available.