A cross platform Audiobookshelf client for Android and iOS
Dart
Use a library's custom skip amounts everywhere, not just after visiting settings
Barnabasef7ca66d28e5
diff --git a/lib/providers/_lp_absorbing.dart b/lib/providers/_lp_absorbing.dartindex 842801d3..3697125e 100644--- a/lib/providers/_lp_absorbing.dart+++ b/lib/providers/_lp_absorbing.dart@@ -304,6 +304,13 @@ mixin _AbsorbingMixin on ChangeNotifier, _StateMixin, _CoreMixin {final key = '$showId-$epId';final cached = _absorbingItemCache[key];if (cached == null) continue;+ // Synthetic merged-library entries are built from show maps that+ // may lack a libraryId; without it the card controls and playback+ // fall back to the global skip amounts.+ final cachedLibId = cached['libraryId'] as String?;+ if (cachedLibId == null || cachedLibId.isEmpty) {+ cached['libraryId'] = fullItem['libraryId'];+ }final ep = episodes.cast<Map<String, dynamic>?>().firstWhere((e) => e != null && (e['id'] as String?) == epId,orElse: () => null,diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dartindex dde19afb..ce0b669d 100644--- a/lib/services/audio_player_service.dart+++ b/lib/services/audio_player_service.dart@@ -461,6 +461,7 @@ class AudioPlayerHandler extends BaseAudioHandler with SeekHandler {debugPrint('[Handler] fastForward() - seeking forward');final skipAmount = await PlayerSettings.getEffectiveForwardSkip(libraryId: _service?.currentLibraryId);+ debugPrint('[SkipDebug] fastForward: lib=${_service?.currentLibraryId} amount=${skipAmount}s');if (_service != null) {await _service!.skipForward(skipAmount);} else {@@ -474,6 +475,7 @@ class AudioPlayerHandler extends BaseAudioHandler with SeekHandler {debugPrint('[Handler] rewind() - seeking back');final skipAmount = await PlayerSettings.getEffectiveBackSkip(libraryId: _service?.currentLibraryId);+ debugPrint('[SkipDebug] rewind: lib=${_service?.currentLibraryId} amount=${skipAmount}s');if (_service != null) {await _service!.skipBackward(skipAmount);} else {@@ -1263,6 +1265,7 @@ class AudioPlayerService extends ChangeNotifier {void _syncNotifSkipCache() {final libId = _currentLibraryId;PlayerSettings.getEffectiveForwardSkip(libraryId: libId).then((v) {+ debugPrint('[SkipDebug] notif cache: lib=$libId fwd=${v}s (was ${_handler?._cachedForwardSkip})');if (_handler != null && v != _handler!._cachedForwardSkip) {_handler!._cachedForwardSkip = v;_handler!.refreshPlaybackState();@@ -1276,6 +1279,42 @@ class AudioPlayerService extends ChangeNotifier {});}+ /// Fill in a missing library id for the playing item so per-library skip+ /// amounts apply outside the in-app UI too (notification, headset, home+ /// widget, Android Auto). Lean shelf items and merged-library podcast+ /// entries often arrive without one; try download metadata synchronously,+ /// then the server.+ void _resolveMissingLibraryId(String itemId, String? episodeId) {+ if (itemId.isEmpty) return;+ if (_currentLibraryId != null && _currentLibraryId!.isNotEmpty) return;+ final key = episodeId != null ? '$itemId-$episodeId' : itemId;+ final fromDownload = DownloadService().getInfo(key).libraryId;+ if (fromDownload != null && fromDownload.isNotEmpty) {+ debugPrint('[SkipDebug] libraryId resolved from download metadata: $fromDownload');+ _currentLibraryId = fromDownload;+ return;+ }+ final api = _api;+ if (api == null) return;+ unawaited(() async {+ try {+ final item = await api.getLibraryItem(itemId);+ final libId = item?['libraryId'] as String?;+ if (libId == null || libId.isEmpty) return;+ // Only adopt if this item is still the one playing and nothing else+ // resolved the library in the meantime (e.g. the play session).+ if (_currentItemId != itemId) return;+ if (_currentLibraryId != null && _currentLibraryId!.isNotEmpty) return;+ debugPrint('[SkipDebug] libraryId resolved from server: $libId');+ _currentLibraryId = libId;+ _syncNotifSkipCache();+ notifyListeners();+ } catch (e) {+ debugPrint('[SkipDebug] libraryId lookup failed: $e');+ }+ }());+ }+/// The last seek target in seconds (absolute book position)./// UI can use this to immediately snap to the target before stream catches up.double? _lastSeekTargetSeconds;@@ -1578,6 +1617,7 @@ class AudioPlayerService extends ChangeNotifier {_currentItemId = next['itemId'] as String?;_currentEpisodeId = next['episodeId'] as String?;_currentLibraryId = next['libraryId'] as String?;+ _resolveMissingLibraryId(_currentItemId ?? '', _currentEpisodeId);_syncNotifSkipCache();_currentTitle = next['title'] as String?;_currentAuthor = next['author'] as String?;@@ -2445,6 +2485,8 @@ class AudioPlayerService extends ChangeNotifier {_currentItemId = itemId;_currentEpisodeId = episodeId;_currentLibraryId = libraryId;+ debugPrint('[SkipDebug] playItem libraryId=$libraryId (item=$itemId ep=$episodeId)');+ _resolveMissingLibraryId(itemId, episodeId);_syncNotifSkipCache();// Reset local-session mode for every new play; _playFromLocal re-enables it// for downloaded items. Without this it leaks from a prior downloaded play@@ -3078,6 +3120,15 @@ class AudioPlayerService extends ChangeNotifier {}_playbackSessionId = sessionData['id'] as String?;+ // Sessions know their library; adopt it when the caller couldn't provide+ // one so per-library skip amounts work for lean/merged shelf items.+ final sessionLibId = sessionData['libraryId'] as String?;+ if ((_currentLibraryId == null || _currentLibraryId!.isEmpty) &&+ sessionLibId != null && sessionLibId.isNotEmpty) {+ debugPrint('[SkipDebug] libraryId adopted from play session: $sessionLibId');+ _currentLibraryId = sessionLibId;+ _syncNotifSkipCache();+ }_lastServerSync = DateTime.now();_logEvent(PlaybackEventType.sessionStart, detail: 'stream');var audioTracks = sessionData['audioTracks'] as List<dynamic>?;diff --git a/lib/widgets/absorbing_card.dart b/lib/widgets/absorbing_card.dartindex 927b30cb..439d67d6 100644--- a/lib/widgets/absorbing_card.dart+++ b/lib/widgets/absorbing_card.dart@@ -1129,7 +1129,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveClicoverUrl: _coverUrl, totalDuration: _effectiveDuration, chapters: _chapters,episodeId: _episodeId,episodeTitle: _recentEpisode?['title'] as String?,- libraryId: widget.item['libraryId'] as String?,+ libraryId: _resolveLibraryId(),);if (mounted) {if (error != null) showErrorSnackBar(context, error);diff --git a/lib/widgets/episode_detail_sheet.dart b/lib/widgets/episode_detail_sheet.dartindex 074aebc0..ec10bde6 100644--- a/lib/widgets/episode_detail_sheet.dart+++ b/lib/widgets/episode_detail_sheet.dart@@ -134,7 +134,9 @@ class _EpisodeDetailSheetState extends State<EpisodeDetailSheet> {coverUrl: api.getCoverUrl(_itemId), totalDuration: _duration, chapters: _chapters,episodeId: _episodeId,episodeTitle: _episodeTitle,- libraryId: context.read<LibraryProvider>().selectedLibraryId,+ // The show's own library, not the browsing library (wrong with unified+ // libraries on). Null lets the player resolve it from the session.+ libraryId: widget.podcastItem['libraryId'] as String?,);debugPrint('[PodcastPlay] playItem returned in ${DateTime.now().difference(t0).inMilliseconds}ms (error=${error ?? 'none'})');if (error != null && rootContext.mounted) {diff --git a/lib/widgets/episode_list_sheet.dart b/lib/widgets/episode_list_sheet.dartindex 881f6a40..e36673e9 100644--- a/lib/widgets/episode_list_sheet.dart+++ b/lib/widgets/episode_list_sheet.dart@@ -326,7 +326,11 @@ class _EpisodeListSheetState extends State<EpisodeListSheet> {chapters: chapters,episodeId: episodeId,episodeTitle: episodeTitle,- libraryId: context.read<LibraryProvider>().selectedLibraryId,+ // The show's own library, not the browsing library - with unified+ // libraries on, this sheet can open shows from other libraries and the+ // selected library would pin the wrong per-library skip amounts. Null+ // is fine: the player resolves it from the session/server.+ libraryId: widget.podcastItem['libraryId'] as String?,);if (mounted) {if (error != null) showErrorSnackBar(context, error);diff --git a/lib/widgets/expanded_card.dart b/lib/widgets/expanded_card.dartindex 099afa75..99eed710 100644--- a/lib/widgets/expanded_card.dart+++ b/lib/widgets/expanded_card.dart@@ -1105,7 +1105,7 @@ class _ExpandedCardState extends State<ExpandedCard> {coverUrl: _coverUrl, totalDuration: _effectiveDuration, chapters: _chapters,episodeId: _episodeId,episodeTitle: _recentEpisode?['title'] as String?,- libraryId: _item['libraryId'] as String?,+ libraryId: _resolveLibraryId(),);if (mounted) {if (error != null) showErrorSnackBar(context, error);diff --git a/lib/widgets/podcast_episode_feed.dart b/lib/widgets/podcast_episode_feed.dartindex bfd59bf0..e3b6cdb7 100644--- a/lib/widgets/podcast_episode_feed.dart+++ b/lib/widgets/podcast_episode_feed.dart@@ -224,7 +224,10 @@ class _PodcastEpisodeFeedState extends State<PodcastEpisodeFeed> {chapters: chapters,episodeId: episodeId,episodeTitle: title,- libraryId: widget.libraryId,+ // Prefer the show's own library - the feed can aggregate shows from+ // other libraries when unified libraries is on.+ libraryId: (ep['podcast'] as Map<String, dynamic>?)?['libraryId'] as String? ??+ widget.libraryId,);if (error != null && mounted) showErrorSnackBar(context, error);}