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