Fix the playback speed value

This commit is contained in:
Bnyro 2022-10-28 22:26:33 +02:00
parent 67982186c6
commit c5fb672d44
3 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1,9 @@
package com.github.libretube.extensions
import kotlin.math.pow
import kotlin.math.roundToInt
fun Float.round(decimalPlaces: Int): Float {
return (this * 10.0.pow(decimalPlaces.toDouble())).roundToInt() / 10.0.pow(decimalPlaces.toDouble())
.toFloat()
}

View File

@ -6,6 +6,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import com.github.libretube.databinding.PlaybackBottomSheetBinding
import com.github.libretube.extensions.round
import com.google.android.exoplayer2.PlaybackParameters
import com.google.android.exoplayer2.Player
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
@ -31,11 +32,11 @@ class PlaybackSpeedSheet(
binding.pitch.value = player.playbackParameters.pitch
binding.speed.addOnChangeListener { _, value, _ ->
onChange(value, binding.pitch.value)
onChange(value, binding.pitch.value.round(2))
}
binding.pitch.addOnChangeListener { _, value, _ ->
onChange(binding.speed.value, value)
onChange(binding.speed.value.round(2), value)
}
}