# rememberPooledPlayer

## Functions summary

|---|---|
| `T?` | `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://developer.android.com/reference/kotlin/androidx/media3/common/Player> https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/lifecycle/rememberPooledPlayer.composable#rememberPooledPlayer(androidx.media3.common.MediaItem,androidx.media3.common.PlayerPool,kotlin.Function1,kotlin.Function1)( mediaItem: https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem, playerPool: https://developer.android.com/reference/kotlin/androidx/media3/common/PlayerPool<T>, playerSetup: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html, playerTeardown: ((T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? )` Acquires, configures, and manages the lifecycle of a pooled `https://developer.android.com/reference/kotlin/androidx/media3/common/Player` instance. |

## Functions

### rememberPooledPlayer

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/lifecycle/player.kt+function:rememberPooledPlayer)

```
@UnstableApi
@Composable
fun <T : Player> rememberPooledPlayer(
    mediaItem: MediaItem,
    playerPool: PlayerPool<T>,
    playerSetup: (T) -> Unit,
    playerTeardown: ((T) -> Unit)? = null
): T?
```

Acquires, configures, and manages the lifecycle of a pooled `https://developer.android.com/reference/kotlin/androidx/media3/common/Player` instance.

This composable handles the asynchronous acquisition of a player from the provided `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/lifecycle/package-summary#rememberPooledPlayer(androidx.media3.common.MediaItem,androidx.media3.common.PlayerPool,kotlin.Function1,kotlin.Function1)`, suspending if the pool is currently exhausted. Once acquired, it delegates configuration to the `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/lifecycle/package-summary#rememberPooledPlayer(androidx.media3.common.MediaItem,androidx.media3.common.PlayerPool,kotlin.Function1,kotlin.Function1)` lambda. The player is returned to the pool when the component leaves the composition or the underlying `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/lifecycle/package-summary#rememberPooledPlayer(androidx.media3.common.MediaItem,androidx.media3.common.PlayerPool,kotlin.Function1,kotlin.Function1)` changes.

| Parameters |
|---|---|
| `<T : https://developer.android.com/reference/kotlin/androidx/media3/common/Player>` | The specific `https://developer.android.com/reference/kotlin/androidx/media3/common/Player` implementation managed by the pool (e.g., `ExoPlayer`). |
| `mediaItem: https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem` this player will represent. Acts as a key to restart the effect if the content changes. |
| `playerPool: https://developer.android.com/reference/kotlin/androidx/media3/common/PlayerPool<T>` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/PlayerPool` used to acquire and recycle player instances. |
| `playerSetup: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A lambda invoked once the player is successfully acquired. This is where implementation-specific configuration, such as setting the media source and preparing the player, should be performed. |
| `playerTeardown: ((T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? = null` | An optional lambda invoked before the player is returned to the pool. This can be used to perform cleanup or unregister listeners. |

| Returns |
|---|---|
| `T?` | The acquired `https://developer.android.com/reference/kotlin/androidx/media3/common/Player` instance, or `null` if the player is still being acquired or the pool is exhausted. |