Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Stop the progress bar showing further than it is while paused

Barnabas0ba658cd9d95
diff --git a/lib/widgets/card_edge_progress_bar.dart b/lib/widgets/card_edge_progress_bar.dart
index e0d75d14..422e397c 100644
--- a/lib/widgets/card_edge_progress_bar.dart
+++ b/lib/widgets/card_edge_progress_bar.dart
@@ -197,6 +197,13 @@ class _CardEdgeProgressBarState extends State<CardEdgeProgressBar>
if (seekTarget != null && (seekTarget - _lastKnownPos).abs() > 2.0) {
return seekTarget;
}
+ // Paused while active: trust the engine's real position (the position
+ // stream only ticks during playback, so a stale seed could leave the bar
+ // ahead of reality until the next play).
+ if (widget.isActive && !_isPlaying) {
+ final realPos = widget.player.position.inMilliseconds / 1000.0;
+ if (realPos > 0) return realPos;
+ }
if (!widget.isActive || !_isPlaying) return _lastKnownPos;
final elapsed = DateTime.now().difference(_lastPosTime).inMilliseconds / 1000.0;
return _lastKnownPos + elapsed * _currentSpeed;
diff --git a/lib/widgets/card_progress_bar.dart b/lib/widgets/card_progress_bar.dart
index 6f0daf23..6aa6ce11 100644
--- a/lib/widgets/card_progress_bar.dart
+++ b/lib/widgets/card_progress_bar.dart
@@ -201,6 +201,15 @@ class _CardDualProgressBarState extends State<CardDualProgressBar> with WidgetsB
if (seekTarget != null && (seekTarget - _lastKnownPos).abs() > 2.0) {
return seekTarget;
}
+ // Paused while active: trust the engine's real position. The position
+ // stream only ticks during playback, so a stale seed / last-known value
+ // could otherwise leave the bar sitting ahead of the actual position until
+ // the next play (TestFlight: bar appears further than it is, snaps back on
+ // play).
+ if (widget.isActive && !_isPlaying) {
+ final realPos = widget.player.position.inMilliseconds / 1000.0;
+ if (realPos > 0) return realPos;
+ }
if (!widget.isActive || !_isPlaying) return _lastKnownPos;
// Use the player's real position as the baseline instead of interpolating
// from a potentially stale stream event. This prevents overshoot when the