# PlaylistState

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/PlaylistState.kt+class:androidx.media3.ui.compose.state.PlaylistState)


```
@UnstableApi
class PlaylistState
```

<br />

*** ** * ** ***

State that holds information about the current playback playlist.

This state does not have a one-on-one relationship with a UI component like a button, icon, or slider. Instead, it logically groups various playlist-related concepts and values that can be displayed on the screen dynamically.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlaylistState#PlaylistState(androidx.media3.common.Player)(player: https://developer.android.com/reference/kotlin/androidx/media3/common/Player?)` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlaylistState#getMediaItemAt(kotlin.Int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem` at the given `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlaylistState#getMediaItemAt(kotlin.Int)` in the playlist. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlaylistState#observe()()` Subscribes to updates from `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events` and listens to |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlaylistState#seekToMediaItem(kotlin.Int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Seeks to the default position of the media item at the given index in the playlist. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlaylistState#currentMediaItemIndex()` The index of the current `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlaylistState#mediaItemCount()` The total number of media items in the playlist. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlaylistState#playlistMetadata()` The `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata` of the entire playlist. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlaylistState#timeline()` The current `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline` of the player. |

## Public constructors

### PlaylistState

```
PlaylistState(player: Player?)
```

| Parameters |
|---|---|
| `player: https://developer.android.com/reference/kotlin/androidx/media3/common/Player?` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/Player` instance to observe. |

## Public functions

### getMediaItemAt

```
fun getMediaItemAt(index: Int): MediaItem
```

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem` at the given `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/state/PlaylistState#getMediaItemAt(kotlin.Int)` in the playlist.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if the index is out of bounds. |

### observe

```
suspend fun observe(): Unit
```

Subscribes to updates from `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Events` and listens to

- `https://developer.android.com/reference/kotlin/androidx/media3/common/Player#EVENT_TIMELINE_CHANGED()`

- `https://developer.android.com/reference/kotlin/androidx/media3/common/Player#EVENT_POSITION_DISCONTINUITY()`

- `https://developer.android.com/reference/kotlin/androidx/media3/common/Player#EVENT_PLAYLIST_METADATA_CHANGED()`

- `https://developer.android.com/reference/kotlin/androidx/media3/common/Player#EVENT_AVAILABLE_COMMANDS_CHANGED()`

### seekToMediaItem

```
fun seekToMediaItem(index: Int): Unit
```

Seeks to the default position of the media item at the given index in the playlist.

This method does nothing if the player is null or `https://developer.android.com/reference/kotlin/androidx/media3/common/Player#COMMAND_SEEK_TO_MEDIA_ITEM()` is not available.

| Parameters |
|---|---|
| `index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the media item to seek to. |

## Public properties

### currentMediaItemIndex

```
val currentMediaItemIndex: Int
```

The index of the current `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem`. `https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET()` if playlist is empty or command is not available.

### mediaItemCount

```
val mediaItemCount: Int
```

The total number of media items in the playlist. 0 if playlist is empty or command is not available.

### playlistMetadata

```
val playlistMetadata: MediaMetadata
```

The `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata` of the entire playlist. `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaMetadata#EMPTY()` if not set or command is not available.

### timeline

```
val timeline: Timeline
```

The current `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline` of the player. `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline#EMPTY()` if playlist is empty or command is not available.