mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 15:30:31 +05:30
Apply playback params for all players
This commit is contained in:
parent
b03d080316
commit
79fab618df
@ -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.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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user