rememberPooledPlayer

Functions summary

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

Acquires, configures, and manages the lifecycle of a pooled Player instance.

Functions

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 Player instance.

This composable handles the asynchronous acquisition of a player from the provided playerPool, suspending if the pool is currently exhausted. Once acquired, it delegates configuration to the playerSetup lambda. The player is returned to the pool when the component leaves the composition or the underlying mediaItem changes.

Parameters
<T : Player>

The specific Player implementation managed by the pool (e.g., ExoPlayer).

mediaItem: MediaItem

The MediaItem this player will represent. Acts as a key to restart the effect if the content changes.

playerPool: PlayerPool<T>

The PlayerPool used to acquire and recycle player instances.

playerSetup: (T) -> Unit

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) -> Unit)? = 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 Player instance, or null if the player is still being acquired or the pool is exhausted.