Merge pull request #4368 from Bnyro/master

fix: respect preference to not start playing automatically everywhere
This commit is contained in:
Bnyro 2023-08-04 18:38:04 +02:00 committed by GitHub
commit 278d9312b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 12 deletions

View File

@ -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

View File

@ -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
}

View File

@ -216,7 +216,7 @@ class OnlinePlayerService : LifecycleService() {
streams?.let { onNewVideo?.invoke(it, videoId) }
player?.apply {
playWhenReady = true
playWhenReady = PlayerHelper.playAutomatically
prepare()
}

View File

@ -156,8 +156,8 @@ class OfflinePlayerActivity : BaseActivity() {
OfflineTimeFrameReceiver(this@OfflinePlayerActivity, it)
}
player.playWhenReady = PlayerHelper.playAutomatically
player.prepare()
player.play()
}
}

View File

@ -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 ->

View File

@ -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