From 4ff2ed38c7921426d2f523db6d9793936b661f18 Mon Sep 17 00:00:00 2001 From: Midori Kochiya Date: Mon, 11 Mar 2024 15:13:13 +0800 Subject: [PATCH] Fix load control for F-Droid builds --- .../cappielloantonio/tempo/service/MediaService.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/notquitemy/java/com/cappielloantonio/tempo/service/MediaService.kt b/app/src/notquitemy/java/com/cappielloantonio/tempo/service/MediaService.kt index 614a6661..6bcd6330 100644 --- a/app/src/notquitemy/java/com/cappielloantonio/tempo/service/MediaService.kt +++ b/app/src/notquitemy/java/com/cappielloantonio/tempo/service/MediaService.kt @@ -8,6 +8,7 @@ import android.content.Intent import android.os.Bundle import androidx.media3.common.* import androidx.media3.common.util.UnstableApi +import androidx.media3.exoplayer.DefaultLoadControl import androidx.media3.exoplayer.ExoPlayer import androidx.media3.exoplayer.source.DefaultMediaSourceFactory import androidx.media3.exoplayer.source.TrackGroupArray @@ -18,6 +19,7 @@ import com.cappielloantonio.tempo.R import com.cappielloantonio.tempo.ui.activity.MainActivity import com.cappielloantonio.tempo.util.Constants import com.cappielloantonio.tempo.util.DownloadUtil +import com.cappielloantonio.tempo.util.Preferences import com.cappielloantonio.tempo.util.ReplayGainUtil import com.google.common.collect.ImmutableList import com.google.common.util.concurrent.Futures @@ -143,6 +145,7 @@ class MediaService : MediaLibraryService() { .setAudioAttributes(AudioAttributes.DEFAULT, true) .setHandleAudioBecomingNoisy(true) .setWakeMode(C.WAKE_MODE_NETWORK) + .setLoadControl(initializeLoadControl()) .build() } @@ -249,6 +252,17 @@ class MediaService : MediaLibraryService() { /* Do nothing. */ } + private fun initializeLoadControl(): DefaultLoadControl { + return DefaultLoadControl.Builder() + .setBufferDurationsMs( + (DefaultLoadControl.DEFAULT_MIN_BUFFER_MS * Preferences.getBufferingStrategy()).toInt(), + (DefaultLoadControl.DEFAULT_MAX_BUFFER_MS * Preferences.getBufferingStrategy()).toInt(), + DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS, + DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS + ) + .build() + } + private fun getRenderersFactory() = DownloadUtil.buildRenderersFactory(this, false) private fun getMediaSourceFactory() =