# PlayerStateObserver

Artifact: [androidx.media3:media3-ui-compose](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/ui/compose/state/PlayerStateObserver.kt+class:androidx.media3.ui.compose.state.PlayerStateObserver)


```
@UnstableApi
class PlayerStateObserver
```

<br />

*** ** * ** ***

Utility to observe `https://developer.android.com/reference/kotlin/androidx/media3/common/Player` states by listening to events.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver#PlayerStateObserver(androidx.media3.common.Player,kotlin.Int,kotlin.IntArray,kotlin.Function1)( player: https://developer.android.com/reference/kotlin/androidx/media3/common/Player, firstEvent: @https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, vararg otherEvents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, stateUpdater: (https://developer.android.com/reference/kotlin/androidx/media3/common/Player) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Creates a `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver` that triggers `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver#(androidx.media3.common.Player,kotlin.Int,kotlin.IntArray,kotlin.Function1)` initially and whenever one of the configured events happen. |
| `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver#PlayerStateObserver(androidx.media3.common.Player,kotlin.Int,kotlin.IntArray,kotlin.Function2)( player: https://developer.android.com/reference/kotlin/androidx/media3/common/Player, firstEvent: @https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, vararg otherEvents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, stateUpdater: (https://developer.android.com/reference/kotlin/androidx/media3/common/Player, https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Creates a `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver` that triggers `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver#(androidx.media3.common.Player,kotlin.Int,kotlin.IntArray,kotlin.Function2)` initially (with all configured `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events`) and whenever one of the configured events happen. |
| `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver#PlayerStateObserver(androidx.media3.common.Player,kotlin.Int,kotlin.IntArray,kotlin.Function1,kotlin.Function2)( player: https://developer.android.com/reference/kotlin/androidx/media3/common/Player, firstEvent: @https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, vararg otherEvents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, initialStateUpdater: (https://developer.android.com/reference/kotlin/androidx/media3/common/Player) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html, stateUpdater: (https://developer.android.com/reference/kotlin/androidx/media3/common/Player, https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` |

| ### Public functions |
|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-nothing/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver#observe()()` Observes updates from the configured `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events`. |

## Public constructors

### PlayerStateObserver

```
PlayerStateObserver(
    player: Player,
    firstEvent: @Player.Event Int,
    vararg otherEvents: Int,
    stateUpdater: (Player) -> Unit
)
```

Creates a `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver` that triggers `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver#(androidx.media3.common.Player,kotlin.Int,kotlin.IntArray,kotlin.Function1)` initially and whenever one of the configured events happen.

| Parameters |
|---|---|
| `player: https://developer.android.com/reference/kotlin/androidx/media3/common/Player` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/Player`. |
| `firstEvent: @https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The first `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event` to listen to. |
| `vararg otherEvents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Additional `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event` types to listen to. |
| `stateUpdater: (https://developer.android.com/reference/kotlin/androidx/media3/common/Player) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The operation to trigger initially and whenever one of the configured events happen. |

### PlayerStateObserver

```
PlayerStateObserver(
    player: Player,
    firstEvent: @Player.Event Int,
    vararg otherEvents: Int,
    stateUpdater: (Player, Player.Events) -> Unit
)
```

Creates a `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver` that triggers `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver#(androidx.media3.common.Player,kotlin.Int,kotlin.IntArray,kotlin.Function2)` initially (with all configured `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events`) and whenever one of the configured events happen.

| Parameters |
|---|---|
| `player: https://developer.android.com/reference/kotlin/androidx/media3/common/Player` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/Player`. |
| `firstEvent: @https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The first `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event` to listen to. |
| `vararg otherEvents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Additional `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event` types to listen to. |
| `stateUpdater: (https://developer.android.com/reference/kotlin/androidx/media3/common/Player, https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The operation to trigger initially (with all configured `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events`) and whenever one of the configured events happen. |

### PlayerStateObserver

```
PlayerStateObserver(
    player: Player,
    firstEvent: @Player.Event Int,
    vararg otherEvents: Int,
    initialStateUpdater: (Player) -> Unit,
    stateUpdater: (Player, Player.Events) -> Unit
)
```

| Parameters |
|---|---|
| `player: https://developer.android.com/reference/kotlin/androidx/media3/common/Player` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/Player`. |
| `firstEvent: @https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The first `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event` to listen to. |
| `vararg otherEvents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Additional `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Event` types to listen to. |
| `initialStateUpdater: (https://developer.android.com/reference/kotlin/androidx/media3/common/Player) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The operation to trigger initially on creation and when `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlayerStateObserver#observe()` starts. |
| `stateUpdater: (https://developer.android.com/reference/kotlin/androidx/media3/common/Player, https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The operation to trigger whenever one of the configured events happen. The provided `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events` contains only the subset of configured events that occurred. |

## Public functions

### observe

```
suspend fun observe(): Nothing
```

Observes updates from the configured `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events`.