mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Option to manage Playback Speed of Audio and Video Mode Separately
This commit is contained in:
parent
f4c3077ffb
commit
1366578f5a
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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<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) {
|
||||
|
@ -441,6 +441,8 @@
|
||||
<string name="faq">FAQ</string>
|
||||
<string name="codecs">Codecs</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 -->
|
||||
<string name="download_channel_name">Download Service</string>
|
||||
<string name="download_channel_description">Shows a notification when downloading media.</string>
|
||||
|
@ -161,6 +161,26 @@
|
||||
|
||||
</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">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
|
Loading…
Reference in New Issue
Block a user