Fix service not stopping on play

Listen for player `isPlaying` then stop background service if it is running.
This commit is contained in:
Krunal Patel 2022-11-29 21:38:30 +05:30
parent f8676682bf
commit e1100db58e

View File

@ -194,9 +194,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
context?.hideKeyboard(view) context?.hideKeyboard(view)
// Stop [BackgroundMode] service if it is running.
BackgroundHelper.stopBackgroundPlay(requireContext())
// clear the playing queue // clear the playing queue
PlayingQueue.resetToDefaults() PlayingQueue.resetToDefaults()
@ -317,8 +314,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
} }
binding.playImageView.setOnClickListener { binding.playImageView.setOnClickListener {
// Stop [BackgroundMode] service if it is running.
BackgroundHelper.stopBackgroundPlay(requireContext())
if (!exoPlayer.isPlaying) { if (!exoPlayer.isPlaying) {
// start or go on playing // start or go on playing
binding.playImageView.setImageResource(R.drawable.ic_pause) binding.playImageView.setImageResource(R.drawable.ic_pause)
@ -819,6 +814,11 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
// Listener for play and pause icon change // Listener for play and pause icon change
exoPlayer.addListener(object : Player.Listener { exoPlayer.addListener(object : Player.Listener {
override fun onIsPlayingChanged(isPlaying: Boolean) { override fun onIsPlayingChanged(isPlaying: Boolean) {
if (isPlaying) {
// Stop [BackgroundMode] service if it is running.
BackgroundHelper.stopBackgroundPlay(requireContext())
}
if (isPlaying && PlayerHelper.sponsorBlockEnabled) { if (isPlaying && PlayerHelper.sponsorBlockEnabled) {
Handler(Looper.getMainLooper()).postDelayed( Handler(Looper.getMainLooper()).postDelayed(
this@PlayerFragment::checkForSegments, this@PlayerFragment::checkForSegments,