Merge pull request #5102 from Bnyro/master

fix: multiple seekbar listeners interfering with each other
This commit is contained in:
Bnyro 2023-11-03 14:31:02 +01:00 committed by GitHub
commit 705231a4fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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() {
@ -759,7 +761,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()
@ -1021,6 +1022,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() {
@ -1532,22 +1540,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)
}
)
) )
} }