mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
fix: respect preference to not start playing automatically everywhere
This commit is contained in:
parent
d3d78a93ce
commit
3495649669
@ -322,6 +322,13 @@ object PlayerHelper {
|
||||
"all"
|
||||
)
|
||||
|
||||
val playAutomatically: Boolean
|
||||
get() = PreferenceHelper
|
||||
.getBoolean(
|
||||
PreferenceKeys.PLAY_AUTOMATICALLY,
|
||||
true
|
||||
)
|
||||
|
||||
fun getDefaultResolution(context: Context): String {
|
||||
val prefKey = if (NetworkHelper.isNetworkMetered(context)) {
|
||||
PreferenceKeys.DEFAULT_RESOLUTION_MOBILE
|
||||
|
@ -83,9 +83,7 @@ class OfflinePlayerService : LifecycleService() {
|
||||
.setAudioAttributes(PlayerHelper.getAudioAttributes(), true)
|
||||
.setLoadControl(PlayerHelper.getLoadControl())
|
||||
.build()
|
||||
.loadPlaybackParams(isBackgroundMode = true).apply {
|
||||
playWhenReady = true
|
||||
}
|
||||
.loadPlaybackParams(isBackgroundMode = true)
|
||||
|
||||
val audioItem = downloadWithItem.downloadItems.firstOrNull { it.type == FileType.AUDIO }
|
||||
?: // in some rare cases, video files can contain audio
|
||||
@ -96,6 +94,7 @@ class OfflinePlayerService : LifecycleService() {
|
||||
.build()
|
||||
|
||||
player?.setMediaItem(mediaItem)
|
||||
player?.playWhenReady = PlayerHelper.playAutomatically
|
||||
player?.prepare()
|
||||
return true
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ class OnlinePlayerService : LifecycleService() {
|
||||
streams?.let { onNewVideo?.invoke(it, videoId) }
|
||||
|
||||
player?.apply {
|
||||
playWhenReady = true
|
||||
playWhenReady = PlayerHelper.playAutomatically
|
||||
prepare()
|
||||
}
|
||||
|
||||
|
@ -156,8 +156,8 @@ class OfflinePlayerActivity : BaseActivity() {
|
||||
OfflineTimeFrameReceiver(this@OfflinePlayerActivity, it)
|
||||
}
|
||||
|
||||
player.playWhenReady = PlayerHelper.playAutomatically
|
||||
player.prepare()
|
||||
player.play()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
private var transitionEndId = 0
|
||||
|
||||
private var handler = Handler(Looper.getMainLooper())
|
||||
private var isPaused = false
|
||||
private var isPaused = !PlayerHelper.playAutomatically
|
||||
|
||||
private var playerService: OnlinePlayerService? = null
|
||||
|
||||
@ -204,6 +204,8 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
binding.volumeProgressBar.let { bar ->
|
||||
bar.progress = audioHelper.getVolumeWithScale(bar.max)
|
||||
}
|
||||
|
||||
if (!PlayerHelper.playAutomatically) updatePlayPauseButton(false)
|
||||
}
|
||||
|
||||
private fun killFragment() {
|
||||
@ -320,11 +322,15 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
handler.postDelayed(this::updateSeekBar, 200)
|
||||
}
|
||||
|
||||
private fun updatePlayPauseButton(isPlaying: Boolean) {
|
||||
val iconResource = if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play
|
||||
binding.playPause.setIconResource(iconResource)
|
||||
binding.miniPlayerPause.setImageResource(iconResource)
|
||||
}
|
||||
|
||||
private fun handleServiceConnection() {
|
||||
playerService?.onIsPlayingChanged = { isPlaying ->
|
||||
val iconResource = if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play
|
||||
binding.playPause.setIconResource(iconResource)
|
||||
binding.miniPlayerPause.setImageResource(iconResource)
|
||||
updatePlayPauseButton(isPlaying)
|
||||
isPaused = !isPlaying
|
||||
}
|
||||
playerService?.onNewVideo = { streams, videoId ->
|
||||
|
@ -754,10 +754,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
|
||||
if (viewModel.isFullscreen.value == true) updateFullscreenOrientation()
|
||||
|
||||
exoPlayer.playWhenReady = PlayerHelper.playAutomatically
|
||||
exoPlayer.prepare()
|
||||
if (PreferenceHelper.getBoolean(PreferenceKeys.PLAY_AUTOMATICALLY, true)) {
|
||||
exoPlayer.play()
|
||||
}
|
||||
|
||||
if (binding.playerMotionLayout.progress != 1.0f) {
|
||||
// show controllers when not in picture in picture mode
|
||||
|
Loading…
Reference in New Issue
Block a user