Skip to content

Commit

Permalink
feat: implemented streaming buffering strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
CappielloAntonio committed Nov 26, 2023
1 parent 9fde629 commit 0a5983e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down Expand Up @@ -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()
}

}
13 changes: 13 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,17 @@
<item>2</item>
<item>3</item>
</string-array>

<string-array name="buffering_strategy_titles">
<item>Minimum</item>
<item>Moderate</item>
<item>Aggressive</item>
<item>Extreme</item>
</string-array>
<string-array name="buffering_strategy_values">
<item>.1</item>
<item>1</item>
<item>2</item>
<item>4</item>
</string-array>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@
<string name="settings_audio_transcode_priority_summary">If enabled, Tempo will not force stream the track with the transcode settings below.</string>
<string name="settings_audio_transcode_priority_title">Prioritize server transcode settings</string>
<string name="settings_audio_transcode_priority_toast">Priority on transcoding of track given to server</string>
<string name="settings_buffering_strategy">Buffering strategy</string>
<string name="settings_buffering_strategy_summary">For the change to take effect you must manually restart the app.</string>
<string name="settings_covers_cache">Size of artwork cache</string>
<string name="settings_data_saving_mode_summary">In order to reduce data consumption, avoid downloading covers.</string>
<string name="settings_data_saving_mode_title">Limit mobile data usage</string>
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/xml/global_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@
android:summary="@string/settings_sync_starred_tracks_for_offline_use_summary"
android:key="sync_starred_tracks_for_offline_use" />

<ListPreference
app:defaultValue="1"
app:dialogTitle="@string/settings_buffering_strategy"
app:entries="@array/buffering_strategy_titles"
app:entryValues="@array/buffering_strategy_values"
app:key="buffering_strategy"
app:title="@string/settings_buffering_strategy"
app:summary="@string/settings_buffering_strategy_summary"
app:useSimpleSummaryProvider="false" />

<Preference
android:key="download_storage"
app:title="@string/settings_download_storage_title" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -208,7 +209,7 @@ class MediaService : MediaLibraryService(), SessionAvailabilityListener {
.setAudioAttributes(AudioAttributes.DEFAULT, true)
.setHandleAudioBecomingNoisy(true)
.setWakeMode(C.WAKE_MODE_NETWORK)
// .setLoadControl(initializeLoadControl())
.setLoadControl(initializeLoadControl())
.build()
}

Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 0a5983e

Please sign in to comment.