diff --git a/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt b/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt index 578b9fd0..71a8e711 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt +++ b/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt @@ -42,6 +42,7 @@ object Preferences { private const val SHARE = "share" private const val SCROBBLING = "scrobbling" private const val ESTIMATE_CONTENT_LENGTH = "estimate_content_length" + private const val BUFFERING_STRATEGY = "buffering_strategy" @JvmStatic fun getServer(): String? { @@ -331,4 +332,10 @@ object Preferences { fun askForEstimateContentLength(): Boolean { return App.getInstance().preferences.getBoolean(ESTIMATE_CONTENT_LENGTH, false) } + + @JvmStatic + fun getBufferingStrategy(): Double { + return App.getInstance().preferences.getString(BUFFERING_STRATEGY, "1")!!.toDouble() + } + } \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 6cc81ea3..9b47fe91 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -211,4 +211,17 @@ 2 3 + + + Minimum + Moderate + Aggressive + Extreme + + + .1 + 1 + 2 + 4 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index df930e18..99979d04 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -236,6 +236,8 @@ If enabled, Tempo will not force stream the track with the transcode settings below. Prioritize server transcode settings Priority on transcoding of track given to server + Buffering strategy + For the change to take effect you must manually restart the app. Size of artwork cache In order to reduce data consumption, avoid downloading covers. Limit mobile data usage diff --git a/app/src/main/res/xml/global_preferences.xml b/app/src/main/res/xml/global_preferences.xml index 9529326d..b2702929 100644 --- a/app/src/main/res/xml/global_preferences.xml +++ b/app/src/main/res/xml/global_preferences.xml @@ -102,6 +102,16 @@ android:summary="@string/settings_sync_starred_tracks_for_offline_use_summary" android:key="sync_starred_tracks_for_offline_use" /> + + diff --git a/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaService.kt b/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaService.kt index bc7a694e..058d932f 100644 --- a/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaService.kt +++ b/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaService.kt @@ -19,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.android.gms.cast.framework.CastContext import com.google.android.gms.common.ConnectionResult @@ -208,7 +209,7 @@ class MediaService : MediaLibraryService(), SessionAvailabilityListener { .setAudioAttributes(AudioAttributes.DEFAULT, true) .setHandleAudioBecomingNoisy(true) .setWakeMode(C.WAKE_MODE_NETWORK) - // .setLoadControl(initializeLoadControl()) + .setLoadControl(initializeLoadControl()) .build() } @@ -296,8 +297,8 @@ class MediaService : MediaLibraryService(), SessionAvailabilityListener { private fun initializeLoadControl(): DefaultLoadControl { return DefaultLoadControl.Builder() .setBufferDurationsMs( - 60_000, - 120_000, + (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 )