Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fix empty cast progress bar on multi-file books in fallback mode

Nathan Poulson2b61001d970f
diff --git a/lib/widgets/absorbing_card.dart b/lib/widgets/absorbing_card.dart
index 9f71db3b..8b863a06 100644
--- a/lib/widgets/absorbing_card.dart
+++ b/lib/widgets/absorbing_card.dart
@@ -237,12 +237,15 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
if (_isCastingThis) {
final stream = ChromecastService().castPositionStream;
if (stream == null) return;
- _chapterTrackSub = stream.listen((pos) {
+ _chapterTrackSub = stream.listen((_) {
if (!_isCastingThis) return;
- final posS = pos.inMilliseconds / 1000.0;
- final chapters = ChromecastService().castingChapters;
+ // Use translated book-level position from ChromecastService, not the raw
+ // stream value (which is track-local in multi-track fallback mode).
+ final cast = ChromecastService();
+ final posS = cast.castPosition.inMilliseconds / 1000.0;
+ final chapters = cast.castingChapters;
if (chapters.isEmpty) {
- final sec = pos.inSeconds;
+ final sec = cast.castPosition.inSeconds;
if (sec != _lastChapterIdx) {
_lastChapterIdx = sec;
if (mounted) setState(() {});
diff --git a/lib/widgets/card_edge_progress_bar.dart b/lib/widgets/card_edge_progress_bar.dart
index af094431..ba43225d 100644
--- a/lib/widgets/card_edge_progress_bar.dart
+++ b/lib/widgets/card_edge_progress_bar.dart
@@ -141,9 +141,10 @@ class _CardEdgeProgressBarState extends State<CardEdgeProgressBar>
_currentSpeed = cast.castSpeed;
_isPlaying = cast.isPlaying;
_syncTicker();
- _posSub = cast.castPositionStream?.listen((dur) {
- final posSeconds = dur.inMilliseconds / 1000.0;
- _lastKnownPos = posSeconds;
+ _posSub = cast.castPositionStream?.listen((_) {
+ // Read from cast.castPosition (not the raw stream value) so we get the
+ // book-level position after multi-track fallback offset translation.
+ _lastKnownPos = cast.castPosition.inMilliseconds / 1000.0;
_lastPosTime = DateTime.now();
_currentSpeed = cast.castSpeed;
_isPlaying = cast.isPlaying;
diff --git a/lib/widgets/card_progress_bar.dart b/lib/widgets/card_progress_bar.dart
index 24a90027..d98faa18 100644
--- a/lib/widgets/card_progress_bar.dart
+++ b/lib/widgets/card_progress_bar.dart
@@ -112,9 +112,12 @@ class _CardDualProgressBarState extends State<CardDualProgressBar> with WidgetsB
_currentSpeed = cast.castSpeed;
_isPlaying = cast.isPlaying;
_syncTicker();
- _posSub = cast.castPositionStream?.listen((dur) {
- final posSeconds = dur.inMilliseconds / 1000.0;
- _lastKnownPos = posSeconds;
+ _posSub = cast.castPositionStream?.listen((_) {
+ // Read from cast.castPosition (not the raw stream value) so we get the
+ // book-level position after multi-track fallback offset translation.
+ // The chromecast service subscribes to the raw stream first, so by the
+ // time this listener fires, _castPosition is already updated.
+ _lastKnownPos = cast.castPosition.inMilliseconds / 1000.0;
_lastPosTime = DateTime.now();
_currentSpeed = cast.castSpeed;
_isPlaying = cast.isPlaying;
diff --git a/lib/widgets/expanded_card.dart b/lib/widgets/expanded_card.dart
index 149d8229..9b00c2b6 100644
--- a/lib/widgets/expanded_card.dart
+++ b/lib/widgets/expanded_card.dart
@@ -350,12 +350,15 @@ class _ExpandedCardState extends State<ExpandedCard> {
if (_isCastingThis) {
final stream = ChromecastService().castPositionStream;
if (stream == null) return;
- _chapterTrackSub = stream.listen((pos) {
+ _chapterTrackSub = stream.listen((_) {
if (!_isCastingThis) return;
- final posS = pos.inMilliseconds / 1000.0;
- final chapters = ChromecastService().castingChapters;
+ // Use translated book-level position from ChromecastService, not the raw
+ // stream value (which is track-local in multi-track fallback mode).
+ final cast = ChromecastService();
+ final posS = cast.castPosition.inMilliseconds / 1000.0;
+ final chapters = cast.castingChapters;
if (chapters.isEmpty) {
- final sec = pos.inSeconds;
+ final sec = cast.castPosition.inSeconds;
if (sec != _lastChapterIdx) { _lastChapterIdx = sec; if (mounted) setState(() {}); }
return;
}