Merge pull request #3097 from Bnyro/master

Option to manage Playback Speed ​​of Audio and Video Mode Separately
This commit is contained in:
Bnyro 2023-02-16 20:24:06 +01:00 committed by GitHub
commit 7cd8567872
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 8 deletions

View File

@ -56,7 +56,9 @@ object PreferenceKeys {
const val AUTO_FULLSCREEN = "auto_fullscreen" const val AUTO_FULLSCREEN = "auto_fullscreen"
const val AUTO_PLAY = "autoplay" const val AUTO_PLAY = "autoplay"
const val RELATED_STREAMS = "related_streams_toggle" const val RELATED_STREAMS = "related_streams_toggle"
const val CUSTOM_PLAYBACK_SPEED = "custom_playback_speed"
const val PLAYBACK_SPEED = "playback_speed" const val PLAYBACK_SPEED = "playback_speed"
const val BACKGROUND_PLAYBACK_SPEED = "background_playback_speed"
const val FULLSCREEN_ORIENTATION = "fullscreen_orientation" const val FULLSCREEN_ORIENTATION = "fullscreen_orientation"
const val PAUSE_ON_SCREEN_OFF = "pause_screen_off" const val PAUSE_ON_SCREEN_OFF = "pause_screen_off"
const val WATCH_POSITIONS = "watch_positions" const val WATCH_POSITIONS = "watch_positions"

View File

@ -282,11 +282,17 @@ object PlayerHelper {
.roundToInt() .roundToInt()
.toLong() * 1000 .toLong() * 1000
private val playbackSpeed: String private val playbackSpeed: Float
get() = PreferenceHelper.getString( get() = PreferenceHelper.getString(
PreferenceKeys.PLAYBACK_SPEED, PreferenceKeys.PLAYBACK_SPEED,
"1" "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 val resizeModePref: String
get() = PreferenceHelper.getString( get() = PreferenceHelper.getString(
@ -470,12 +476,10 @@ object PlayerHelper {
/** /**
* Load playback parameters such as speed and skip silence * Load playback parameters such as speed and skip silence
*/ */
fun ExoPlayer.loadPlaybackParams(): ExoPlayer { fun ExoPlayer.loadPlaybackParams(isBackgroundMode: Boolean = false): ExoPlayer {
skipSilenceEnabled = skipSilence skipSilenceEnabled = skipSilence
playbackParameters = PlaybackParameters( val speed = if (isBackgroundMode) backgroundSpeed else playbackSpeed
playbackSpeed.toFloat(), playbackParameters = PlaybackParameters(speed, 1.0f)
1.0f
)
return this return this
} }

View File

@ -239,7 +239,7 @@ class BackgroundMode : LifecycleService() {
.setAudioAttributes(PlayerHelper.getAudioAttributes(), true) .setAudioAttributes(PlayerHelper.getAudioAttributes(), true)
.setLoadControl(PlayerHelper.getLoadControl()) .setLoadControl(PlayerHelper.getLoadControl())
.build() .build()
.loadPlaybackParams() .loadPlaybackParams(isBackgroundMode = true)
/** /**
* Listens for changed playbackStates (e.g. pause, end) * Listens for changed playbackStates (e.g. pause, end)

View File

@ -15,6 +15,7 @@ import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.helpers.LocaleHelper import com.github.libretube.helpers.LocaleHelper
import com.github.libretube.helpers.PreferenceHelper import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.ui.views.SliderPreference
class PlayerSettings : BasePreferenceFragment() { class PlayerSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.player override val titleResourceId: Int = R.string.player
@ -70,6 +71,19 @@ class PlayerSettings : BasePreferenceFragment() {
pauseOnQuit?.isVisible = !(newValue as Boolean) pauseOnQuit?.isVisible = !(newValue as Boolean)
true true
} }
val customBackgroundSpeed = findPreference<SwitchPreferenceCompat>(
PreferenceKeys.CUSTOM_PLAYBACK_SPEED
)
val backgroundSpeed = findPreference<SliderPreference>(
PreferenceKeys.BACKGROUND_PLAYBACK_SPEED
)
backgroundSpeed?.isEnabled = customBackgroundSpeed?.isChecked == true
customBackgroundSpeed?.setOnPreferenceChangeListener { _, newValue ->
backgroundSpeed?.isEnabled = newValue as Boolean
true
}
} }
private fun setupSubtitlePref(preference: ListPreference) { private fun setupSubtitlePref(preference: ListPreference) {

View File

@ -441,6 +441,8 @@
<string name="faq">FAQ</string> <string name="faq">FAQ</string>
<string name="codecs">Codecs</string> <string name="codecs">Codecs</string>
<string name="mark_as_watched">Mark as watched</string> <string name="mark_as_watched">Mark as watched</string>
<string name="custom_playback_speed">Custom speed</string>
<string name="custom_playback_speed_summary">Use a different playback speed than for the normal player.</string>
<!-- Notification channel strings --> <!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string> <string name="download_channel_name">Download Service</string>
<string name="download_channel_description">Shows a notification when downloading media.</string> <string name="download_channel_description">Shows a notification when downloading media.</string>

View File

@ -161,6 +161,26 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory app:title="@string/background_mode">
<SwitchPreferenceCompat
app:defaultValue="false"
app:key="custom_playback_speed"
app:title="@string/custom_playback_speed"
android:summary="@string/custom_playback_speed_summary"
android:icon="@drawable/ic_headphones" />
<com.github.libretube.ui.views.SliderPreference
android:icon="@drawable/ic_speed"
app:defValue="1.0"
app:key="background_playback_speed"
app:stepSize="0.1"
app:title="@string/playback_speed"
app:valueFrom="0.2"
app:valueTo="4.0" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/misc"> <PreferenceCategory app:title="@string/misc">
<SwitchPreferenceCompat <SwitchPreferenceCompat