mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 15:30:31 +05:30
Merge pull request #2790 from Bnyro/master
Apply the remembered playback params for all players
This commit is contained in:
commit
7a65a477d9
@ -93,7 +93,6 @@ object PreferenceKeys {
|
||||
/**
|
||||
* Background mode
|
||||
*/
|
||||
const val BACKGROUND_PLAYBACK_SPEED = "background_playback_speed"
|
||||
const val AUDIO_ONLY_MODE = "audio_only_mode"
|
||||
|
||||
/**
|
||||
|
@ -22,7 +22,6 @@ import com.github.libretube.api.obj.Streams
|
||||
import com.github.libretube.constants.BACKGROUND_CHANNEL_ID
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.db.DatabaseHolder.Companion.Database
|
||||
import com.github.libretube.db.obj.WatchPosition
|
||||
import com.github.libretube.extensions.TAG
|
||||
@ -32,8 +31,8 @@ import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.extensions.toStreamItem
|
||||
import com.github.libretube.util.NowPlayingNotification
|
||||
import com.github.libretube.util.PlayerHelper
|
||||
import com.github.libretube.util.PlayerHelper.loadPlaybackParams
|
||||
import com.github.libretube.util.PlayingQueue
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.google.android.exoplayer2.PlaybackException
|
||||
@ -223,13 +222,6 @@ class BackgroundMode : Service() {
|
||||
}
|
||||
}
|
||||
|
||||
// set the playback speed
|
||||
val playbackSpeed = PreferenceHelper.getString(
|
||||
PreferenceKeys.BACKGROUND_PLAYBACK_SPEED,
|
||||
"1"
|
||||
).toFloat()
|
||||
player?.setPlaybackSpeed(playbackSpeed)
|
||||
|
||||
fetchSponsorBlockSegments()
|
||||
}
|
||||
|
||||
@ -244,6 +236,7 @@ class BackgroundMode : Service() {
|
||||
.setAudioAttributes(PlayerHelper.getAudioAttributes(), true)
|
||||
.setLoadControl(PlayerHelper.getLoadControl())
|
||||
.build()
|
||||
.loadPlaybackParams()
|
||||
|
||||
/**
|
||||
* Listens for changed playbackStates (e.g. pause, end)
|
||||
|
@ -20,6 +20,7 @@ import com.github.libretube.ui.base.BaseActivity
|
||||
import com.github.libretube.ui.extensions.setAspectRatio
|
||||
import com.github.libretube.ui.models.PlayerViewModel
|
||||
import com.github.libretube.util.PlayerHelper
|
||||
import com.github.libretube.util.PlayerHelper.loadPlaybackParams
|
||||
import com.github.libretube.util.WindowHelper
|
||||
import com.google.android.exoplayer2.C
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
@ -81,6 +82,7 @@ class OfflinePlayerActivity : BaseActivity() {
|
||||
}
|
||||
})
|
||||
}
|
||||
.loadPlaybackParams()
|
||||
|
||||
playerView = binding.player
|
||||
playerView.setShowSubtitleButton(true)
|
||||
|
@ -94,6 +94,7 @@ import com.github.libretube.util.LinkHandler
|
||||
import com.github.libretube.util.NavigationHelper
|
||||
import com.github.libretube.util.NowPlayingNotification
|
||||
import com.github.libretube.util.PlayerHelper
|
||||
import com.github.libretube.util.PlayerHelper.loadPlaybackParams
|
||||
import com.github.libretube.util.PlayingQueue
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.github.libretube.util.SeekbarPreviewListener
|
||||
@ -1346,6 +1347,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
.setHandleAudioBecomingNoisy(true)
|
||||
.setAudioAttributes(PlayerHelper.getAudioAttributes(), true)
|
||||
.build()
|
||||
.loadPlaybackParams()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,6 @@ import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.databinding.DoubleTapOverlayBinding
|
||||
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||
import com.github.libretube.databinding.PlayerGestureControlsViewBinding
|
||||
@ -36,9 +35,7 @@ import com.github.libretube.util.BrightnessHelper
|
||||
import com.github.libretube.util.PlayerGestureController
|
||||
import com.github.libretube.util.PlayerHelper
|
||||
import com.github.libretube.util.PlayingQueue
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.PlaybackParameters
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.google.android.exoplayer2.text.Cue
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelector
|
||||
@ -92,9 +89,6 @@ internal class CustomExoPlayerView(
|
||||
if (isControllerFullyVisible) hideController() else showController()
|
||||
}
|
||||
|
||||
// saved to only load the playback speed once (for the first video)
|
||||
private var playbackPrefSet = false
|
||||
|
||||
private val hideControllerRunnable = Runnable {
|
||||
hideController()
|
||||
}
|
||||
@ -127,17 +121,6 @@ internal class CustomExoPlayerView(
|
||||
// don't let the player view hide its controls automatically
|
||||
controllerShowTimeoutMs = -1
|
||||
|
||||
if (!playbackPrefSet) {
|
||||
player?.playbackParameters = PlaybackParameters(
|
||||
PlayerHelper.playbackSpeed.toFloat(),
|
||||
1.0f
|
||||
)
|
||||
PreferenceHelper.getBoolean(PreferenceKeys.SKIP_SILENCE, false).let {
|
||||
(player as ExoPlayer).skipSilenceEnabled = it
|
||||
}
|
||||
playbackPrefSet = true
|
||||
}
|
||||
|
||||
// locking the player
|
||||
binding.lockPlayer.setOnClickListener {
|
||||
// change the locked/unlocked icon
|
||||
@ -218,9 +201,15 @@ internal class CustomExoPlayerView(
|
||||
}
|
||||
}
|
||||
|
||||
private fun cancelHideControllerTask() {
|
||||
runCatching {
|
||||
handler.removeCallbacks(hideControllerRunnable)
|
||||
}
|
||||
}
|
||||
|
||||
override fun hideController() {
|
||||
// remove the callback to hide the controller
|
||||
handler.removeCallbacks(hideControllerRunnable)
|
||||
cancelHideControllerTask()
|
||||
super.hideController()
|
||||
|
||||
// hide system bars if in fullscreen
|
||||
@ -234,7 +223,7 @@ internal class CustomExoPlayerView(
|
||||
|
||||
override fun showController() {
|
||||
// remove the previous callback from the queue to prevent a flashing behavior
|
||||
handler.removeCallbacks(hideControllerRunnable)
|
||||
cancelHideControllerTask()
|
||||
// automatically hide the controller after 2 seconds
|
||||
handler.postDelayed(hideControllerRunnable, AUTO_HIDE_CONTROLLER_DELAY)
|
||||
super.showController()
|
||||
@ -393,8 +382,8 @@ internal class CustomExoPlayerView(
|
||||
doubleTapOverlayBinding?.apply {
|
||||
animateSeeking(rewindBTN, rewindIV, rewindTV, true)
|
||||
|
||||
runnableHandler.removeCallbacks(hideRewindButtonRunnable)
|
||||
// start callback to hide the button
|
||||
runnableHandler.removeCallbacks(hideRewindButtonRunnable)
|
||||
runnableHandler.postDelayed(hideRewindButtonRunnable, 700)
|
||||
}
|
||||
}
|
||||
@ -718,7 +707,7 @@ internal class CustomExoPlayerView(
|
||||
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
|
||||
// when a control is clicked, restart the countdown to hide the controller
|
||||
if (isControllerFullyVisible) {
|
||||
handler.removeCallbacks(hideControllerRunnable)
|
||||
cancelHideControllerTask()
|
||||
handler.postDelayed(hideControllerRunnable, AUTO_HIDE_CONTROLLER_DELAY)
|
||||
}
|
||||
return super.onInterceptTouchEvent(ev)
|
||||
|
@ -18,7 +18,9 @@ import com.github.libretube.enums.AudioQuality
|
||||
import com.github.libretube.enums.PlayerEvent
|
||||
import com.google.android.exoplayer2.C
|
||||
import com.google.android.exoplayer2.DefaultLoadControl
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.LoadControl
|
||||
import com.google.android.exoplayer2.PlaybackParameters
|
||||
import com.google.android.exoplayer2.audio.AudioAttributes
|
||||
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
||||
import com.google.android.exoplayer2.video.VideoSize
|
||||
@ -342,6 +344,12 @@ object PlayerHelper {
|
||||
false
|
||||
)
|
||||
|
||||
private val skipSilence: Boolean
|
||||
get() = PreferenceHelper.getBoolean(
|
||||
PreferenceKeys.SKIP_SILENCE,
|
||||
false
|
||||
)
|
||||
|
||||
fun getDefaultResolution(context: Context): String {
|
||||
return if (NetworkHelper.isNetworkMobile(context)) {
|
||||
PreferenceHelper.getString(
|
||||
@ -459,4 +467,16 @@ object PlayerHelper {
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* Load playback parameters such as speed and skip silence
|
||||
*/
|
||||
fun ExoPlayer.loadPlaybackParams(): ExoPlayer {
|
||||
skipSilenceEnabled = skipSilence
|
||||
playbackParameters = PlaybackParameters(
|
||||
playbackSpeed.toFloat(),
|
||||
1.0f
|
||||
)
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
@ -78,17 +78,4 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/background_mode">
|
||||
|
||||
<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>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user