A cross platform Audiobookshelf client for Android and iOS
Dart
Fix chapter flash during session load and add speed +/- buttons
Nathan Poulson05ce214b8b59
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dartindex 8ecd56c1..be4bf992 100644--- a/lib/services/audio_player_service.dart+++ b/lib/services/audio_player_service.dart@@ -725,7 +725,7 @@ class AudioPlayerService extends ChangeNotifier {double? get activeSeekTarget {if (_lastSeekTargetSeconds == null || _lastSeekTime == null) return null;final elapsed = DateTime.now().difference(_lastSeekTime!).inMilliseconds;- if (elapsed > 2000) {+ if (elapsed > 8000) {_lastSeekTargetSeconds = null;_lastSeekTime = null;return null;@@ -1006,7 +1006,6 @@ class AudioPlayerService extends ChangeNotifier {_handler?.updateChaptersQueue(chapters);// New book = fresh session — clear any auto sleep dismissalSleepTimerService().resetDismiss();- notifyListeners();// Progress key: compound for episodes, plain for booksfinal progressKey = episodeId != null ? '$itemId-$episodeId' : itemId;@@ -1018,6 +1017,13 @@ class AudioPlayerService extends ChangeNotifier {debugPrint('[Player] Resuming from local position: ${startTime}s');}+ // Set seek target early so the UI doesn't flash chapter 1 while loading+ if (startTime > 0) {+ _lastSeekTargetSeconds = startTime;+ _lastSeekTime = DateTime.now();+ }+ notifyListeners();+// Check if downloaded — play locallyfinal bool result;if (_downloadService.isDownloaded(progressKey)) {diff --git a/lib/widgets/absorbing_card.dart b/lib/widgets/absorbing_card.dartindex ee6444fa..e2cd03c1 100644--- a/lib/widgets/absorbing_card.dart+++ b/lib/widgets/absorbing_card.dart@@ -752,7 +752,12 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCliif (_isCastingThis) {pos = cast.castPosition.inMilliseconds / 1000.0;} else if (_isActive) {- pos = widget.player.position.inMilliseconds / 1000.0;+ final seekTarget = widget.player.activeSeekTarget;+ if (seekTarget != null) {+ pos = seekTarget;+ } else {+ pos = widget.player.position.inMilliseconds / 1000.0;+ }} else {// Use stored progress to calculate position when not actively playingfinal lib = context.read<LibraryProvider>();@@ -777,7 +782,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveClifinal ch = ChromecastService().currentChapter;return ch?['title'] as String?;}- if (_isActive && widget.player.currentChapter != null) {+ if (_isActive && widget.player.activeSeekTarget == null && widget.player.currentChapter != null) {return widget.player.currentChapter!['title'] as String?;}if (chapterIdx >= 0 && chapterIdx < _chapters.length) {diff --git a/lib/widgets/card_buttons.dart b/lib/widgets/card_buttons.dartindex 8fc1e6ef..476721b4 100644--- a/lib/widgets/card_buttons.dart+++ b/lib/widgets/card_buttons.dart@@ -373,8 +373,26 @@ class _CardSpeedSheetState extends State<CardSpeedSheet> {));}).toList()),const SizedBox(height: 16),- AbsorbSlider(value: _speed, min: 0.5, max: 3.0, divisions: 50, activeColor: widget.accent, onChanged: _setSpeed),- Padding(padding: const EdgeInsets.symmetric(horizontal: 12), child: Row(+ Row(children: [+ GestureDetector(+ onTap: () => _setSpeed(_speed - 0.05),+ child: Container(+ width: 36, height: 36,+ decoration: BoxDecoration(shape: BoxShape.circle, color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.08)),+ child: Icon(Icons.remove_rounded, size: 20, color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.7)),+ ),+ ),+ Expanded(child: AbsorbSlider(value: _speed, min: 0.5, max: 3.0, divisions: 50, activeColor: widget.accent, onChanged: _setSpeed)),+ GestureDetector(+ onTap: () => _setSpeed(_speed + 0.05),+ child: Container(+ width: 36, height: 36,+ decoration: BoxDecoration(shape: BoxShape.circle, color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.08)),+ child: Icon(Icons.add_rounded, size: 20, color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.7)),+ ),+ ),+ ]),+ Padding(padding: const EdgeInsets.symmetric(horizontal: 36), child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [Text('0.5x', style: TextStyle(color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.3), fontSize: 11)),diff --git a/lib/widgets/card_progress_bar.dart b/lib/widgets/card_progress_bar.dartindex dc6423fc..056a4909 100644--- a/lib/widgets/card_progress_bar.dart+++ b/lib/widgets/card_progress_bar.dart@@ -209,7 +209,7 @@ class _CardDualProgressBarState extends State<CardDualProgressBar> with TickerPr}}} else if (widget.isActive) {- final chapter = player.currentChapter;+ final chapter = player.activeSeekTarget == null ? player.currentChapter : null;if (chapter != null) {chapterStart = (chapter['start'] as num?)?.toDouble() ?? 0;chapterEnd = (chapter['end'] as num?)?.toDouble() ?? totalDur;