Skip to content

Commit

Permalink
Settle initial playback position in a single phase.
Browse files Browse the repository at this point in the history
  • Loading branch information
ychescale9 committed Feb 26, 2024
1 parent 39b1fc8 commit 811f201
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ internal fun PodcastPlayer(

Player.STATE_ENDED -> {
seekTo(0)
playerPositionMillis = 0
playerPositionMillis = currentPosition.toInt()
onPlayPauseButtonClick()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableIntStateOf
Expand Down Expand Up @@ -66,14 +66,13 @@ internal fun SeekBar(

var currentPositionMillis by remember { mutableIntStateOf(positionMillis) }

var fullTrackWidthPx by remember { mutableIntStateOf(0) }
var activeTrackWidthPx by remember { mutableFloatStateOf(0f) }

LaunchedEffect(positionMillis, durationMillis, fullTrackWidthPx) {
DisposableEffect(positionMillis, durationMillis) {
if (!seeking && durationMillis > 0) {
currentPositionMillis = positionMillis
activeTrackWidthPx = positionMillis.toFloat() / durationMillis.toFloat() * fullTrackWidthPx
}
onDispose { }
}

Box(
Expand Down Expand Up @@ -141,7 +140,9 @@ internal fun SeekBar(
.clip(CircleShape)
) { measurables, constraints ->
val trackPlaceable = measurables.first().measure(constraints)
fullTrackWidthPx = trackPlaceable.width
if (!seeking) {
activeTrackWidthPx = currentPositionMillis / durationMillis.toFloat() * trackPlaceable.width
}
layout(trackPlaceable.width, trackPlaceable.height) {
trackPlaceable.placeRelative(0, 0)
}
Expand Down

0 comments on commit 811f201

Please sign in to comment.