fix the playback speed sheet

This commit is contained in:
Bnyro 2022-10-16 14:20:56 +02:00
parent 4c2d438c58
commit 499be1e1cb
2 changed files with 16 additions and 9 deletions

View File

@ -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

View File

@ -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() {