diff --git a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt index 45de2fafd..cce1a2107 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -56,7 +56,9 @@ object PreferenceKeys { const val AUTO_FULLSCREEN = "auto_fullscreen" const val AUTO_PLAY = "autoplay" const val RELATED_STREAMS = "related_streams_toggle" + const val CUSTOM_PLAYBACK_SPEED = "custom_playback_speed" const val PLAYBACK_SPEED = "playback_speed" + const val BACKGROUND_PLAYBACK_SPEED = "background_playback_speed" const val FULLSCREEN_ORIENTATION = "fullscreen_orientation" const val PAUSE_ON_SCREEN_OFF = "pause_screen_off" const val WATCH_POSITIONS = "watch_positions" diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt index cda4d4cef..ab032a2a8 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -282,11 +282,17 @@ object PlayerHelper { .roundToInt() .toLong() * 1000 - private val playbackSpeed: String + private val playbackSpeed: Float get() = PreferenceHelper.getString( PreferenceKeys.PLAYBACK_SPEED, "1" - ).replace("F", "") + ).replace("F", "").toFloat() + + private val backgroundSpeed: Float + get() = when (PreferenceHelper.getBoolean(PreferenceKeys.CUSTOM_PLAYBACK_SPEED, false)) { + true -> PreferenceHelper.getString(PreferenceKeys.BACKGROUND_PLAYBACK_SPEED, "1").toFloat() + else -> playbackSpeed + } val resizeModePref: String get() = PreferenceHelper.getString( @@ -470,12 +476,10 @@ object PlayerHelper { /** * Load playback parameters such as speed and skip silence */ - fun ExoPlayer.loadPlaybackParams(): ExoPlayer { + fun ExoPlayer.loadPlaybackParams(isBackgroundMode: Boolean = false): ExoPlayer { skipSilenceEnabled = skipSilence - playbackParameters = PlaybackParameters( - playbackSpeed.toFloat(), - 1.0f - ) + val speed = if (isBackgroundMode) backgroundSpeed else playbackSpeed + playbackParameters = PlaybackParameters(speed, 1.0f) return this } diff --git a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt index 2a44f3e6e..b19563967 100644 --- a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt +++ b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt @@ -239,7 +239,7 @@ class BackgroundMode : LifecycleService() { .setAudioAttributes(PlayerHelper.getAudioAttributes(), true) .setLoadControl(PlayerHelper.getLoadControl()) .build() - .loadPlaybackParams() + .loadPlaybackParams(isBackgroundMode = true) /** * Listens for changed playbackStates (e.g. pause, end) diff --git a/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt index 0587ca184..c6d6b05f4 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt @@ -15,6 +15,7 @@ import com.github.libretube.constants.PreferenceKeys import com.github.libretube.helpers.LocaleHelper import com.github.libretube.helpers.PreferenceHelper import com.github.libretube.ui.base.BasePreferenceFragment +import com.github.libretube.ui.views.SliderPreference class PlayerSettings : BasePreferenceFragment() { override val titleResourceId: Int = R.string.player @@ -70,6 +71,19 @@ class PlayerSettings : BasePreferenceFragment() { pauseOnQuit?.isVisible = !(newValue as Boolean) true } + + val customBackgroundSpeed = findPreference( + PreferenceKeys.CUSTOM_PLAYBACK_SPEED + ) + val backgroundSpeed = findPreference( + PreferenceKeys.BACKGROUND_PLAYBACK_SPEED + ) + backgroundSpeed?.isEnabled = customBackgroundSpeed?.isChecked == true + + customBackgroundSpeed?.setOnPreferenceChangeListener { _, newValue -> + backgroundSpeed?.isEnabled = newValue as Boolean + true + } } private fun setupSubtitlePref(preference: ListPreference) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 049356e87..74fdb0f51 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -441,6 +441,8 @@ FAQ Codecs Mark as watched + Custom speed + Use a different playback speed than for the normal player. Download Service Shows a notification when downloading media. diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index 3d3dd39c5..7f438e031 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -161,6 +161,26 @@ + + + + + + + +