Skip to content

Commit

Permalink
Remember more things
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Feb 16, 2024
1 parent 714eff4 commit ed22886
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions ui/src/main/java/com/theoplayer/android/ui/SeekBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,30 @@ fun SeekBar(
val player = Player.current
val currentTime = player?.currentTime?.toFloat() ?: 0.0f
val seekable = player?.seekable ?: TimeRanges(listOf())
val valueRange = seekable.bounds ?: 0.0..0.0

val valueRange = remember(seekable) {
val bounds = seekable.bounds ?: 0.0..0.0
bounds.start.toFloat()..bounds.endInclusive.toFloat()
}
var seekTime by remember { mutableStateOf<Float?>(null) }
var wasPlayingBeforeSeek by remember { mutableStateOf(false) }

Slider(
modifier = modifier,
colors = colors,
value = seekTime ?: currentTime,
valueRange = valueRange.start.toFloat()..valueRange.endInclusive.toFloat(),
valueRange = valueRange,
enabled = seekable.isNotEmpty(),
onValueChange = { time ->
seekTime = time
player?.player?.let {
if (!it.isPaused) {
wasPlayingBeforeSeek = true
it.pause()
onValueChange = remember {
{ time ->
seekTime = time
player?.player?.let {
if (!it.isPaused) {
wasPlayingBeforeSeek = true
it.pause()
}
it.currentTime = time.toDouble()
}
it.currentTime = time.toDouble()
}
},
// This needs to always be the *same* callback,
Expand Down

0 comments on commit ed22886

Please sign in to comment.