@MainThread
@UnstableApi
class PlayerPool<T : Player>


A pool of Player instances.

All operations on this class must be called from the main thread.

Parameters
<T : Player>

The type of the Player instances in the pool.

Summary

Public constructors

<T : Player> PlayerPool(poolCapacity: Int, playerFactory: () -> T)

Public functions

suspend T

Suspends until a player is available in the pool.

Unit

Executes the given action only on players that are currently acquired from the pool.

Unit
@MainThread
executeForAll(action: T.() -> Unit)

Executes the given action on all players managed by the pool, including both acquired players and idle players waiting in the pool.

Unit

Releases all players in the pool and prevents further acquisition.

Unit
yield(player: T)

Returns a player to the pool.

Public constructors

PlayerPool

<T : Player> PlayerPool(poolCapacity: Int, playerFactory: () -> T)
Parameters
<T : Player>

The type of the Player instances in the pool.

poolCapacity: Int

The maximum number of players to hold in the pool. Must be positive.

playerFactory: () -> T

A lambda responsible for instantiating and configuring new players. The created players must be configured to be accessed from the main thread.

Public functions

acquire

suspend fun acquire(): T

Suspends until a player is available in the pool.

executeForAcquired

@MainThread
fun executeForAcquired(action: T.() -> Unit): Unit

Executes the given action only on players that are currently acquired from the pool.

This is useful for broadcasting state changes (like muting or updating playback speed) to players that are currently active, without affecting idle players in the pool.

Parameters
action: T.() -> Unit

The action to perform on each acquired player.

executeForAll

@MainThread
fun executeForAll(action: T.() -> Unit): Unit

Executes the given action on all players managed by the pool, including both acquired players and idle players waiting in the pool.

Parameters
action: T.() -> Unit

The action to perform on each player.

release

fun release(): Unit

Releases all players in the pool and prevents further acquisition.

yield

fun yield(player: T): Unit

Returns a player to the pool.

Parameters
player: T

The Player instance to return to the pool.