Skip to content

Commit

Permalink
Fix progress slider lagged issue on player
Browse files Browse the repository at this point in the history
  • Loading branch information
aidewoode committed Mar 19, 2024
1 parent 4ff3a9b commit 24032b4
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.Slider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
Expand All @@ -35,17 +39,23 @@ fun PlayerControl(
onSeek: (Double) -> Unit,
) {
val progressValue = if (duration > 0) (currentPosition / duration).toFloat() else 0f
var progressValueState by remember { mutableFloatStateOf(0f) }

val currentPositionText = if (enabled) DurationFormatter.string(currentPosition) else NONE_DURATION_TEXT
val durationText = if (enabled) DurationFormatter.string(duration) else NONE_DURATION_TEXT

Column(
modifier = modifier,
) {
Slider(
value = progressValue,
value = if (progressValueState == 0f) progressValue else progressValueState,
enabled = enabled,
onValueChange = {
onSeek(duration * it)
progressValueState = it
},
onValueChangeFinished = {
onSeek(duration * progressValueState)
progressValueState = 0f
},
)

Expand Down

0 comments on commit 24032b4

Please sign in to comment.