playback: fix slider crash

Fix crashes occuring from -1 positions causing Slider to error out.

This is just fixed by band-aiding the UI, since I seemingly cannot
control these from the backend.
This commit is contained in:
Alexander Capehart
2022-11-14 19:43:46 -07:00
parent c9422b7f9d
commit dffa3dc34e
2 changed files with 6 additions and 4 deletions
@@ -69,15 +69,17 @@ constructor(
var positionDs: Long
get() = binding.seekBarSlider.value.toLong()
set(value) {
val sanitized = max(value, 0)
// Sanity check: Ensure that this value is within the duration and will not crash
// the app, and that the user is not currently seeking (which would cause the SeekBar
// to jump around).
if (value <= durationDs && !isActivated) {
binding.seekBarSlider.value = value.toFloat()
if (sanitized <= durationDs && !isActivated) {
binding.seekBarSlider.value = sanitized.toFloat()
// We would want to keep this in the callback, but the callback only fires when
// a value changes completely, and sometimes that does not happen with this view.
binding.seekBarPosition.text = value.formatDurationDs(true)
binding.seekBarPosition.text = sanitized.formatDurationDs(true)
}
}