Makes max exoplayer pool size to a variable in the class

This commit is contained in:
Vitor Pamplona
2025-09-11 11:06:09 -04:00
parent 7f428a9976
commit 2eda4d40e8
2 changed files with 7 additions and 2 deletions
@@ -37,9 +37,9 @@ import java.util.concurrent.ConcurrentLinkedQueue
@OptIn(UnstableApi::class) @OptIn(UnstableApi::class)
class ExoPlayerPool( class ExoPlayerPool(
val builder: ExoPlayerBuilder, val builder: ExoPlayerBuilder,
private val poolSize: Int,
) { ) {
private val playerPool = ConcurrentLinkedQueue<ExoPlayer>() private val playerPool = ConcurrentLinkedQueue<ExoPlayer>()
private val poolSize = SimultaneousPlaybackCalculator.max()
private val poolStartingSize = 3 private val poolStartingSize = 3
// Exists to avoid exceptions stopping the coroutine // Exists to avoid exceptions stopping the coroutine
@@ -33,6 +33,7 @@ import com.vitorpamplona.amethyst.service.playback.pip.BackgroundMedia
import com.vitorpamplona.amethyst.service.playback.playerPool.ExoPlayerBuilder import com.vitorpamplona.amethyst.service.playback.playerPool.ExoPlayerBuilder
import com.vitorpamplona.amethyst.service.playback.playerPool.ExoPlayerPool import com.vitorpamplona.amethyst.service.playback.playerPool.ExoPlayerPool
import com.vitorpamplona.amethyst.service.playback.playerPool.MediaSessionPool import com.vitorpamplona.amethyst.service.playback.playerPool.MediaSessionPool
import com.vitorpamplona.amethyst.service.playback.playerPool.SimultaneousPlaybackCalculator
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
class PlaybackService : MediaSessionService() { class PlaybackService : MediaSessionService() {
@@ -42,7 +43,11 @@ class PlaybackService : MediaSessionService() {
@OptIn(UnstableApi::class) @OptIn(UnstableApi::class)
fun newPool(okHttp: OkHttpClient): MediaSessionPool = fun newPool(okHttp: OkHttpClient): MediaSessionPool =
MediaSessionPool( MediaSessionPool(
ExoPlayerPool(ExoPlayerBuilder(okHttp)), exoPlayerPool =
ExoPlayerPool(
ExoPlayerBuilder(okHttp),
poolSize = SimultaneousPlaybackCalculator.max(applicationContext),
),
okHttpClient = okHttp, okHttpClient = okHttp,
reset = { session, keepPlaying -> reset = { session, keepPlaying ->
(session.player as ExoPlayer).apply { (session.player as ExoPlayer).apply {