mirror of
https://github.com/bbara04/Purefin.git
synced 2026-03-31 17:10:08 +02:00
Fix: Player seekbar ui blocking by only seeking when the seek bar is released
This commit is contained in:
@@ -10,6 +10,11 @@ import androidx.compose.material3.MaterialTheme
|
|||||||
import androidx.compose.material3.Slider
|
import androidx.compose.material3.Slider
|
||||||
import androidx.compose.material3.SliderDefaults
|
import androidx.compose.material3.SliderDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableFloatStateOf
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
@@ -33,10 +38,13 @@ fun PlayerSeekBar(
|
|||||||
) {
|
) {
|
||||||
val scheme = MaterialTheme.colorScheme
|
val scheme = MaterialTheme.colorScheme
|
||||||
val safeDuration = durationMs.takeIf { it > 0 } ?: 1L
|
val safeDuration = durationMs.takeIf { it > 0 } ?: 1L
|
||||||
val position = positionMs.coerceIn(0, safeDuration)
|
val currentPosition = positionMs.coerceIn(0, safeDuration)
|
||||||
|
var sliderPosition by remember { mutableFloatStateOf(currentPosition.toFloat()) }
|
||||||
|
var isScrubbing by remember { mutableStateOf(false) }
|
||||||
|
val sliderValue = if (isScrubbing) sliderPosition else currentPosition.toFloat()
|
||||||
val bufferRatio = (bufferedMs.toFloat() / safeDuration).coerceIn(0f, 1f)
|
val bufferRatio = (bufferedMs.toFloat() / safeDuration).coerceIn(0f, 1f)
|
||||||
val combinedMarkers = chapterMarkers.map { it.copy(type = MarkerType.CHAPTER) } + adMarkers.map { it.copy(type = MarkerType.AD) }
|
val combinedMarkers = chapterMarkers.map { it.copy(type = MarkerType.CHAPTER) } + adMarkers.map { it.copy(type = MarkerType.AD) }
|
||||||
val progressRatio = (position.toFloat() / safeDuration).coerceIn(0f, 1f)
|
val progressRatio = (sliderValue / safeDuration).coerceIn(0f, 1f)
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
@@ -90,12 +98,20 @@ fun PlayerSeekBar(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Slider(
|
Slider(
|
||||||
value = position.toFloat(),
|
value = sliderValue,
|
||||||
onValueChange = { newValue ->
|
onValueChange = { newValue ->
|
||||||
onScrubStarted()
|
if (!isScrubbing) {
|
||||||
onSeek(newValue.toLong())
|
isScrubbing = true
|
||||||
|
onScrubStarted()
|
||||||
|
}
|
||||||
|
sliderPosition = newValue
|
||||||
|
},
|
||||||
|
onValueChangeFinished = {
|
||||||
|
val targetPosition = sliderPosition.toLong().coerceIn(0L, safeDuration)
|
||||||
|
isScrubbing = false
|
||||||
|
onSeek(targetPosition)
|
||||||
|
onScrubFinished()
|
||||||
},
|
},
|
||||||
onValueChangeFinished = onScrubFinished,
|
|
||||||
valueRange = 0f..safeDuration.toFloat(),
|
valueRange = 0f..safeDuration.toFloat(),
|
||||||
colors = SliderDefaults.colors(
|
colors = SliderDefaults.colors(
|
||||||
thumbColor = Color.Transparent,
|
thumbColor = Color.Transparent,
|
||||||
|
|||||||
Reference in New Issue
Block a user