From bc54390f315b0ffa6cf58b812763da4517c409d6 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 13 Jan 2023 19:02:13 +0100 Subject: [PATCH] Fix issues with the seekbar --- .../libretube/ui/fragments/AudioPlayerFragment.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt index 266454a11..ac6299c93 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt @@ -97,18 +97,22 @@ class AudioPlayerFragment : BaseFragment() { } ImageHelper.loadImage(current.thumbnail, binding.thumbnail) + + initializeSeekBar() } private fun initializeSeekBar() { - binding.timeBar.valueTo = playerService.getDuration()?.toFloat() ?: return + if (!this::playerService.isInitialized) return + + binding.timeBar.valueTo = (playerService.getDuration()?.toFloat() ?: return) / 1000 binding.timeBar.addOnChangeListener { _, value, fromUser -> - if (fromUser) playerService.seekToPosition(value.toLong()) + if (fromUser) playerService.seekToPosition(value.toLong() * 1000) } updateCurrentPosition() } private fun updateCurrentPosition() { - binding.timeBar.value = playerService.getCurrentPosition()?.toFloat() ?: 0f + binding.timeBar.value = (playerService.getCurrentPosition()?.toFloat() ?: 0f) / 1000 handler.postDelayed(this::updateCurrentPosition, 200) }