Add max bitrate preference

This commit is contained in:
Damontecres 2025-10-08 21:37:10 -04:00
parent 730a578117
commit 560e7cc545
No known key found for this signature in database
5 changed files with 55 additions and 0 deletions

View file

@ -254,6 +254,52 @@ sealed interface AppPreference<T> {
},
)
private const val MEGA_BIT = 1024 * 1024L
const val DEFAULT_BITRATE = 20 * MEGA_BIT
private val bitrateValues =
listOf(
500 * 1024L,
750 * 1024L,
1 * MEGA_BIT,
2 * MEGA_BIT,
3 * MEGA_BIT,
5 * MEGA_BIT,
8 * MEGA_BIT,
10 * MEGA_BIT,
15 * MEGA_BIT,
DEFAULT_BITRATE,
*(30..100 step 10).map { it * MEGA_BIT }.toTypedArray(),
*(120..200 step 20).map { it * MEGA_BIT }.toTypedArray(),
)
val MaxBitrate =
AppSliderPreference(
title = R.string.max_bitrate,
defaultValue = bitrateValues.indexOf(DEFAULT_BITRATE).toLong(),
min = 0,
max = bitrateValues.size - 1L,
interval = 1,
getter = {
bitrateValues.indexOf(it.playbackPreferences.maxBitrate).toLong()
},
setter = { prefs, value ->
prefs.updatePlaybackPreferences {
maxBitrate = bitrateValues[value.toInt()]
}
},
summarizer = { value ->
if (value != null) {
val v = bitrateValues.getOrNull(value.toInt()) ?: DEFAULT_BITRATE
if (v < MEGA_BIT) {
"${v / 1024} kbps"
} else {
"${v / MEGA_BIT} Mbps"
}
} else {
null
}
},
)
val RememberSelectedTab =
AppSwitchPreference(
title = R.string.remember_selected_tab,
@ -326,6 +372,7 @@ val basicPreferences =
AppPreference.AutoPlayNextUp,
AppPreference.AutoPlayNextDelay,
AppPreference.SkipBackOnResume,
AppPreference.MaxBitrate,
AppPreference.PlaybackDebugInfo,
),
),

View file

@ -33,6 +33,7 @@ class AppPreferencesSerializer
AppPreference.AutoPlayNextDelay.defaultValue
skipBackOnResumeSeconds =
AppPreference.SkipBackOnResume.defaultValue.seconds.inWholeMilliseconds
maxBitrate = AppPreference.DEFAULT_BITRATE
}.build()
homePagePreferences =
HomePagePreferences

View file

@ -16,6 +16,7 @@ import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer
import com.github.damontecres.dolphin.data.model.BaseItem
import com.github.damontecres.dolphin.data.model.Chapter
import com.github.damontecres.dolphin.preferences.AppPreference
import com.github.damontecres.dolphin.preferences.UserPreferences
import com.github.damontecres.dolphin.ui.DefaultItemFields
import com.github.damontecres.dolphin.ui.indexOfFirstOrNull
@ -267,6 +268,9 @@ class PlaybackViewModel
Timber.i("No change in playback for changeStreams")
return
}
val maxBitrate =
preferences.appPreferences.playbackPreferences.maxBitrate
.takeIf { it > 0 } ?: AppPreference.DEFAULT_BITRATE
val response =
api.mediaInfoApi
.getPostedPlaybackInfo(
@ -284,6 +288,7 @@ class PlaybackViewModel
autoOpenLiveStream = true,
mediaSourceId = null,
alwaysBurnInSubtitleWhenTranscoding = null,
maxStreamingBitrate = maxBitrate.toInt(),
),
).content
val source = response.mediaSources.firstOrNull()

View file

@ -12,6 +12,7 @@ message PlaybackPreferences {
bool auto_play_next = 6;
int64 auto_play_next_delay_seconds = 7;
int64 skip_back_on_resume_seconds = 8;
int64 max_bitrate = 9;
}
message HomePagePreferences{

View file

@ -61,5 +61,6 @@
<string name="confirm">Confirm</string>
<string name="remember_selected_tab">Remember selected tabs</string>
<string name="director">Director</string>
<string name="max_bitrate">Max bitrate</string>
</resources>