From 499be1e1cb3d48b1dc31c9f02ef86594eab44606 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 16 Oct 2022 14:20:56 +0200 Subject: [PATCH] fix the playback speed sheet --- .../libretube/ui/sheets/PlaybackSpeedSheet.kt | 18 +++++++++++++++--- .../libretube/ui/views/CustomExoPlayerView.kt | 7 +------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt index 099641ba5..43f28e6b2 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt @@ -6,10 +6,12 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.FragmentManager import com.github.libretube.databinding.PlaybackBottomSheetBinding +import com.google.android.exoplayer2.PlaybackParameters +import com.google.android.exoplayer2.Player import com.google.android.material.bottomsheet.BottomSheetDialogFragment class PlaybackSpeedSheet( - private val onChange: (speed: Float, pitch: Float) -> Unit + private val player: Player ) : BottomSheetDialogFragment() { private lateinit var binding: PlaybackBottomSheetBinding @@ -25,15 +27,25 @@ class PlaybackSpeedSheet( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + binding.speed.value = player.playbackParameters.speed + binding.pitch.value = player.playbackParameters.pitch + binding.speed.addOnChangeListener { _, value, _ -> - onChange.invoke(value, binding.pitch.value) + onChange(value, binding.pitch.value) } binding.pitch.addOnChangeListener { _, value, _ -> - onChange.invoke(binding.speed.value, value) + onChange(binding.speed.value, value) } } + private fun onChange(speed: Float, pitch: Float) { + player.playbackParameters = PlaybackParameters( + speed, + pitch + ) + } + fun show(fragmentManager: FragmentManager) = show( fragmentManager, null diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index dd46b2ceb..eee4a48d1 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -322,12 +322,7 @@ internal class CustomExoPlayerView( } private fun onPlaybackSpeedClicked() { - PlaybackSpeedSheet { speed, pitch -> - player?.playbackParameters = PlaybackParameters( - speed, - pitch - ) - }.show(childFragmentManager) + player?.let { PlaybackSpeedSheet(it).show(childFragmentManager) } } private fun onResizeModeClicked() {