fix: multiple seekbar listeners interfering with each other

This commit is contained in:
Bnyro 2023-11-03 14:30:44 +01:00
parent f0fd37e690
commit 1efe09d492

View File

@ -183,11 +183,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
private var sponsorBlockConfig = PlayerHelper.getSponsorBlockCategories() private var sponsorBlockConfig = PlayerHelper.getSponsorBlockCategories()
private val handler = Handler(Looper.getMainLooper()) private val handler = Handler(Looper.getMainLooper())
private val mainActivity get() = activity as MainActivity
private val windowInsetsControllerCompat
get() = WindowCompat
.getInsetsController(mainActivity.window, mainActivity.window.decorView)
private var seekBarPreviewListener: SeekbarPreviewListener? = null
private var scrubbingTimeBar = false private var scrubbingTimeBar = false
private var chaptersBottomSheet: ChaptersBottomSheet? = null private var chaptersBottomSheet: ChaptersBottomSheet? = null
@ -197,6 +194,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
*/ */
private var playerLayoutOrientation = Int.MIN_VALUE private var playerLayoutOrientation = Int.MIN_VALUE
private val mainActivity get() = activity as MainActivity
private val windowInsetsControllerCompat
get() = WindowCompat
.getInsetsController(mainActivity.window, mainActivity.window.decorView)
private val fullscreenDialog by lazy { private val fullscreenDialog by lazy {
object : Dialog(requireContext(), android.R.style.Theme_Black_NoTitleBar_Fullscreen) { object : Dialog(requireContext(), android.R.style.Theme_Black_NoTitleBar_Fullscreen) {
override fun onBackPressed() { override fun onBackPressed() {
@ -758,7 +760,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
playerBinding.exoProgress.setPlayer(exoPlayer) playerBinding.exoProgress.setPlayer(exoPlayer)
initializePlayerView() initializePlayerView()
setupSeekbarPreview()
exoPlayer.playWhenReady = PlayerHelper.playAutomatically exoPlayer.playWhenReady = PlayerHelper.playAutomatically
exoPlayer.prepare() exoPlayer.prepare()
@ -1020,6 +1021,13 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
playerBinding.skipNext.setOnClickListener { playerBinding.skipNext.setOnClickListener {
playNextVideo() playNextVideo()
} }
// seekbar preview setup
playerBinding.seekbarPreview.isGone = true
seekBarPreviewListener?.let { playerBinding.exoProgress.removeListener(it) }
seekBarPreviewListener = createSeekbarPreviewListener().also {
playerBinding.exoProgress.addListener(it)
}
} }
private fun showAutoPlayCountdown() { private fun showAutoPlayCountdown() {
@ -1531,22 +1539,19 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
} }
.build() .build()
private fun setupSeekbarPreview() { private fun createSeekbarPreviewListener(): SeekbarPreviewListener {
playerBinding.seekbarPreview.isGone = true return SeekbarPreviewListener(
playerBinding.exoProgress.addListener( OnlineTimeFrameReceiver(requireContext(), streams.previewFrames),
SeekbarPreviewListener( playerBinding,
OnlineTimeFrameReceiver(requireContext(), streams.previewFrames), streams.duration * 1000,
playerBinding, onScrub = {
streams.duration * 1000, setCurrentChapterName(forceUpdate = true, enqueueNew = false)
onScrub = { scrubbingTimeBar = true
setCurrentChapterName(forceUpdate = true, enqueueNew = false) },
scrubbingTimeBar = true onScrubEnd = {
}, scrubbingTimeBar = false
onScrubEnd = { setCurrentChapterName(forceUpdate = true, enqueueNew = false)
scrubbingTimeBar = false }
setCurrentChapterName(forceUpdate = true, enqueueNew = false)
}
)
) )
} }