mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
fix the playback speed sheet
This commit is contained in:
parent
4c2d438c58
commit
499be1e1cb
@ -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
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user