Skip to content

Commit 62f2660

Browse files
committed
fix: web progress bar now reflects actual playback time
Remove aggressive near-end snapping (10% threshold) that caused the slider to jump to 100% too early. Reduce update throttle from 1s to 250ms for smoother progress tracking.
1 parent ab51ab9 commit 62f2660

1 file changed

Lines changed: 4 additions & 28 deletions

File tree

mediaplayer/src/webMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.web.kt

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -362,38 +362,14 @@ open class DefaultVideoPlayerState : VideoPlayerState {
362362
forceUpdate: Boolean = false,
363363
) {
364364
val now = TimeSource.Monotonic.markNow()
365-
if (forceUpdate || now - lastUpdateTime >= 1.seconds) {
366-
// Calculate a dynamic threshold based on video duration (10% of duration or at least 0.5 seconds)
367-
val threshold =
368-
if (duration > 0f && !duration.isNaN()) {
369-
maxOf(duration * 0.1f, 0.5f)
370-
} else {
371-
0.5f
372-
}
373-
374-
// Check if we're very close to the end of the video
375-
val isNearEnd =
376-
duration > 0f &&
377-
!duration.isNaN() &&
378-
!currentTime.isNaN() &&
379-
(duration - currentTime < threshold)
380-
381-
// If we're near the end, use the duration as the current time
382-
val displayTime = if (isNearEnd) duration else currentTime
383-
384-
_positionText = if (displayTime.isNaN()) "00:00" else formatTime(displayTime)
365+
if (forceUpdate || now - lastUpdateTime >= 250.milliseconds) {
366+
_positionText = if (currentTime.isNaN()) "00:00" else formatTime(currentTime)
385367
_durationText = if (duration.isNaN()) "00:00" else formatTime(duration)
386368

387-
// Update the current time property
388-
_currentTime = displayTime.toDouble()
369+
_currentTime = currentTime.toDouble()
389370

390371
if (!userDragging && duration > 0f && !duration.isNaN() && !_isLoading) {
391-
sliderPos =
392-
if (isNearEnd) {
393-
PERCENTAGE_MULTIPLIER // Set to 100% if near end
394-
} else {
395-
(currentTime / duration) * PERCENTAGE_MULTIPLIER
396-
}
372+
sliderPos = (currentTime / duration) * PERCENTAGE_MULTIPLIER
397373
}
398374
_currentDuration = duration
399375
lastUpdateTime = now

0 commit comments

Comments
 (0)