A cross platform Audiobookshelf client for Android and iOS
Dart
Fix preview resume and wording issues
Barnabas7d461fa83186
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arbindex 108409af..ddf17acc 100644--- a/lib/l10n/app_en.arb+++ b/lib/l10n/app_en.arb@@ -1500,6 +1500,7 @@}},"selectAll": "Select All",+ "deselectAll": "Deselect All","autoDownloadThisPodcast": "Auto-Download This Podcast?","autoDownloadPodcastContent": "Automatically download the next episodes as you listen.","download": "Download",@@ -3963,7 +3964,6 @@"bookmarkListen": "Listen","bookmarkPause": "Pause","bookmarkPreviewFailed": "Couldn't play this spot.",- "previewSample": "Preview","clipExport": "Export clip","clipJumpToStart": "Jump to start",diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dartindex 3aa7b6a5..a7774a47 100644--- a/lib/l10n/app_localizations.dart+++ b/lib/l10n/app_localizations.dart@@ -5416,6 +5416,12 @@ abstract class AppLocalizations {/// **'Select All'**String get selectAll;+ /// No description provided for @deselectAll.+ ///+ /// In en, this message translates to:+ /// **'Deselect All'**+ String get deselectAll;+/// No description provided for @autoDownloadThisPodcast.////// In en, this message translates to:@@ -11589,12 +11595,6 @@ abstract class AppLocalizations {/// **'Couldn\'t play this spot.'**String get bookmarkPreviewFailed;- /// No description provided for @previewSample.- ///- /// In en, this message translates to:- /// **'Preview'**- String get previewSample;-/// No description provided for @clipExport.////// In en, this message translates to:diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dartindex d0aaf4dd..87470243 100644--- a/lib/l10n/app_localizations_de.dart+++ b/lib/l10n/app_localizations_de.dart@@ -3010,6 +3010,9 @@ class AppLocalizationsDe extends AppLocalizations {@overrideString get selectAll => 'Alle auswählen';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast =>'Diesen Podcast automatisch herunterladen?';@@ -6761,9 +6764,6 @@ class AppLocalizationsDe extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Stelle konnte nicht wiedergeben werden.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Clip exportieren';diff --git a/lib/l10n/app_localizations_el.dart b/lib/l10n/app_localizations_el.dartindex a9712263..4069ff39 100644--- a/lib/l10n/app_localizations_el.dart+++ b/lib/l10n/app_localizations_el.dart@@ -2971,6 +2971,9 @@ class AppLocalizationsEl extends AppLocalizations {@overrideString get selectAll => 'Select All';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast => 'Auto-Download This Podcast?';@@ -6666,9 +6669,6 @@ class AppLocalizationsEl extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Couldn\'t play this spot.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Export clip';diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dartindex 3cc268ae..5a0d5746 100644--- a/lib/l10n/app_localizations_en.dart+++ b/lib/l10n/app_localizations_en.dart@@ -2971,6 +2971,9 @@ class AppLocalizationsEn extends AppLocalizations {@overrideString get selectAll => 'Select All';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast => 'Auto-Download This Podcast?';@@ -6666,9 +6669,6 @@ class AppLocalizationsEn extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Couldn\'t play this spot.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Export clip';diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dartindex 91775a47..20e625fd 100644--- a/lib/l10n/app_localizations_es.dart+++ b/lib/l10n/app_localizations_es.dart@@ -2973,6 +2973,9 @@ class AppLocalizationsEs extends AppLocalizations {@overrideString get selectAll => 'Select All';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast => 'Auto-Download This Podcast?';@@ -6668,9 +6671,6 @@ class AppLocalizationsEs extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Couldn\'t play this spot.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Export clip';diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dartindex ae53f7f7..10ffb73c 100644--- a/lib/l10n/app_localizations_fr.dart+++ b/lib/l10n/app_localizations_fr.dart@@ -2991,6 +2991,9 @@ class AppLocalizationsFr extends AppLocalizations {@overrideString get selectAll => 'Select All';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast => 'Auto-Download This Podcast?';@@ -6686,9 +6689,6 @@ class AppLocalizationsFr extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Couldn\'t play this spot.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Export clip';diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dartindex 96020903..9ace3bfc 100644--- a/lib/l10n/app_localizations_it.dart+++ b/lib/l10n/app_localizations_it.dart@@ -2971,6 +2971,9 @@ class AppLocalizationsIt extends AppLocalizations {@overrideString get selectAll => 'Select All';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast => 'Auto-Download This Podcast?';@@ -6666,9 +6669,6 @@ class AppLocalizationsIt extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Couldn\'t play this spot.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Export clip';diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dartindex 933ffad4..5e8ad435 100644--- a/lib/l10n/app_localizations_ja.dart+++ b/lib/l10n/app_localizations_ja.dart@@ -2971,6 +2971,9 @@ class AppLocalizationsJa extends AppLocalizations {@overrideString get selectAll => 'Select All';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast => 'Auto-Download This Podcast?';@@ -6666,9 +6669,6 @@ class AppLocalizationsJa extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Couldn\'t play this spot.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Export clip';diff --git a/lib/l10n/app_localizations_no.dart b/lib/l10n/app_localizations_no.dartindex 171a5754..9ba4b508 100644--- a/lib/l10n/app_localizations_no.dart+++ b/lib/l10n/app_localizations_no.dart@@ -2971,6 +2971,9 @@ class AppLocalizationsNo extends AppLocalizations {@overrideString get selectAll => 'Select All';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast => 'Auto-Download This Podcast?';@@ -6666,9 +6669,6 @@ class AppLocalizationsNo extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Couldn\'t play this spot.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Export clip';diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dartindex 02c6d026..40048470 100644--- a/lib/l10n/app_localizations_pt.dart+++ b/lib/l10n/app_localizations_pt.dart@@ -2971,6 +2971,9 @@ class AppLocalizationsPt extends AppLocalizations {@overrideString get selectAll => 'Select All';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast => 'Auto-Download This Podcast?';@@ -6666,9 +6669,6 @@ class AppLocalizationsPt extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Couldn\'t play this spot.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Export clip';diff --git a/lib/l10n/app_localizations_ro.dart b/lib/l10n/app_localizations_ro.dartindex 1804fea9..6a265293 100644--- a/lib/l10n/app_localizations_ro.dart+++ b/lib/l10n/app_localizations_ro.dart@@ -2971,6 +2971,9 @@ class AppLocalizationsRo extends AppLocalizations {@overrideString get selectAll => 'Select All';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast => 'Auto-Download This Podcast?';@@ -6666,9 +6669,6 @@ class AppLocalizationsRo extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Couldn\'t play this spot.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Export clip';diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dartindex 66891b6d..0864400b 100644--- a/lib/l10n/app_localizations_ru.dart+++ b/lib/l10n/app_localizations_ru.dart@@ -2975,6 +2975,9 @@ class AppLocalizationsRu extends AppLocalizations {@overrideString get selectAll => 'Select All';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast => 'Auto-Download This Podcast?';@@ -6671,9 +6674,6 @@ class AppLocalizationsRu extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Не удалось воспроизвести это место.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Export clip';diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dartindex 4ba7b410..56fa7323 100644--- a/lib/l10n/app_localizations_zh.dart+++ b/lib/l10n/app_localizations_zh.dart@@ -2902,6 +2902,9 @@ class AppLocalizationsZh extends AppLocalizations {@overrideString get selectAll => '全选';+ @override+ String get deselectAll => 'Deselect All';+@overrideString get autoDownloadThisPodcast => '自动下载此播客?';@@ -6574,9 +6577,6 @@ class AppLocalizationsZh extends AppLocalizations {@overrideString get bookmarkPreviewFailed => 'Couldn\'t play this spot.';- @override- String get previewSample => 'Preview';-@overrideString get clipExport => 'Export clip';diff --git a/lib/screens/downloads_screen.dart b/lib/screens/downloads_screen.dartindex a34d5d9d..7a00ca23 100644--- a/lib/screens/downloads_screen.dart+++ b/lib/screens/downloads_screen.dart@@ -177,6 +177,12 @@ class _DownloadsScreenState extends State<DownloadsScreen> {final cs = Theme.of(context).colorScheme;final tt = Theme.of(context).textTheme;final l = AppLocalizations.of(context)!;+ final allSelected = _selecting &&+ () {+ final visible = _visibleCompleted();+ return visible.isNotEmpty &&+ visible.every((d) => _selected.contains(d.itemId));+ }();return Scaffold(backgroundColor: Theme.of(context).scaffoldBackgroundColor,@@ -197,9 +203,12 @@ class _DownloadsScreenState extends State<DownloadsScreen> {),if (_selecting) ...[IconButton(- icon: Icon(Icons.select_all_rounded,+ icon: Icon(+ allSelected+ ? Icons.deselect_rounded+ : Icons.select_all_rounded,color: cs.onSurfaceVariant),- tooltip: l.selectAll,+ tooltip: allSelected ? l.deselectAll : l.selectAll,onPressed: _toggleSelectAll,),IconButton(diff --git a/lib/services/bookmark_preview_player.dart b/lib/services/bookmark_preview_player.dartindex e828869b..683a0691 100644--- a/lib/services/bookmark_preview_player.dart+++ b/lib/services/bookmark_preview_player.dart@@ -37,6 +37,13 @@ class BookmarkPreviewPlayer extends ChangeNotifier {/// preview is exactly what an export would produce.Duration clipLength = const Duration(seconds: 60);+ /// When true, the clip-length timer and the natural end of the audio fully+ /// [stop] the audition (resuming the main player) instead of just pausing.+ /// The bookmark dialog leaves this false - there the audited book is+ /// usually the one loaded in the main player, and yanking it back to life+ /// mid-edit would be jarring.+ bool stopOnClipEnd = false;+List<BookTrack>? _tracks;bool get isLoading => _loading;@@ -52,7 +59,7 @@ class BookmarkPreviewPlayer extends ChangeNotifier {_autoStop?.cancel();await p.pause();} else {- _pauseMain();+ await _pauseMain();// Restart from the clip start so every replay auditions the beginning// of the selection (also recovers from the auto-stop at the clip end).if (_lastSeekMs != null) {@@ -69,7 +76,7 @@ class BookmarkPreviewPlayer extends ChangeNotifier {Future<void> _playAt(double globalSeconds) async {_loading = true;notifyListeners();- _pauseMain();+ await _pauseMain();final tracks = await _resolveTracks();if (_disposed) return;@@ -101,7 +108,13 @@ class BookmarkPreviewPlayer extends ChangeNotifier {s.processingState == ProcessingState.buffering;_playing = s.playing && !done;notifyListeners();- if (done) player.pause();+ if (done) {+ if (stopOnClipEnd) {+ unawaited(stop());+ } else {+ player.pause();+ }+ }});if (track.local) {await player.setAudioSource(localAudioSource(track.source));@@ -118,6 +131,7 @@ class BookmarkPreviewPlayer extends ChangeNotifier {await player.play();} catch (e) {debugPrint('[BookmarkPreview] $itemId: playback error: $e');+ if (_disposed) return;_loading = false;notifyListeners();rethrow;@@ -129,17 +143,21 @@ class BookmarkPreviewPlayer extends ChangeNotifier {return _tracks;}- void _pauseMain() {+ Future<void> _pauseMain() async {final main = AudioPlayerService();_mainWasPlaying ??= main.isPlaying;- if (main.isPlaying) main.pause();+ if (main.isPlaying) await main.pause();}void _startAutoStop() {_autoStop?.cancel();_autoStop = Timer(clipLength, () {debugPrint('[BookmarkPreview] auto-stop after ${clipLength.inSeconds}s');- _player?.pause();+ if (stopOnClipEnd) {+ unawaited(stop());+ } else {+ _player?.pause();+ }});}@@ -163,10 +181,19 @@ class BookmarkPreviewPlayer extends ChangeNotifier {/// Stop the audition and resume the main player if we had paused it.Future<void> stop() async {await _disposePlayer();- if (_mainWasPlaying == true) {- _mainWasPlaying = null;- await AudioPlayerService().play();- }+ // Reset the snapshot even when it's false, or a sheet-lifetime player's+ // second audition would pause the main book and never resume it.+ final shouldResume = _mainWasPlaying == true;+ _mainWasPlaying = null;+ if (shouldResume) await AudioPlayerService().play();+ if (!_disposed) notifyListeners();+ }++ /// Tear down the audition without resuming the main player - for callers+ /// about to start real playback themselves.+ Future<void> discard() async {+ _mainWasPlaying = null;+ await _disposePlayer();if (!_disposed) notifyListeners();}diff --git a/lib/widgets/book_detail_sheet.dart b/lib/widgets/book_detail_sheet.dartindex ac40fa82..06945edf 100644--- a/lib/widgets/book_detail_sheet.dart+++ b/lib/widgets/book_detail_sheet.dart@@ -448,8 +448,11 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {final isEbookOnly = PlayerSettings.isEbookOnly(_item!);// Preview only makes sense before the book has been started. The 60s- // grace means an accidental tap-and-close doesn't hide it forever.- final showPreview = !isEbookOnly && !isFinished && currentTime < 60 && duration > 0;+ // grace means an accidental tap-and-close doesn't hide it forever. Check+ // the override-aware progress fraction too - the server currentTime can+ // lag local playback.+ final showPreview = !isEbookOnly && !isFinished && currentTime < 60 &&+ progress * duration < 60 && duration > 0;return ListView(controller: widget.scrollController, padding: EdgeInsets.fromLTRB(20, 8, 20, 32 + MediaQuery.of(context).viewPadding.bottom), children: [Center(child: Container(width: 40, height: 4, margin: const EdgeInsets.only(bottom: 16),@@ -728,7 +731,7 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {Icon((_preview?.isPlaying ?? false) ? Icons.stop_rounded : Icons.headphones_rounded,size: 16, color: cs.onSurfaceVariant),const SizedBox(width: 6),- Text((_preview?.isPlaying ?? false) ? l.chapterStopPreview : l.previewSample,+ Text((_preview?.isPlaying ?? false) ? l.chapterStopPreview : l.preview,style: TextStyle(color: cs.onSurfaceVariant, fontSize: 12, fontWeight: FontWeight.w500)),]),),@@ -1932,6 +1935,7 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {}_preview ??= BookmarkPreviewPlayer(itemId: widget.itemId, api: context.read<AuthProvider>().apiService)..clipLength = const Duration(minutes: 5)+ ..stopOnClipEnd = true..addListener(_onPreviewChanged);final startAt = _previewStartSeconds(chapters, duration);debugPrint('[BookDetail] preview start at ${startAt.toStringAsFixed(1)}s of ${duration.toStringAsFixed(0)}s');@@ -1950,7 +1954,9 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {}Future<void> _startAbsorb(BuildContext context, {required AuthProvider auth, required String title, required String author, required String? coverUrl, required double duration, required List<dynamic> chapters}) async {- await _preview?.stop();+ // Discard, not stop: we're about to start playback ourselves, so briefly+ // resuming the previous book would just be an audible blip.+ await _preview?.discard();final player = AudioPlayerService();// Grab the root navigator before we pop the sheetfinal rootNav = Navigator.of(context, rootNavigator: true);