A cross platform Audiobookshelf client for Android and iOS
Dart
Play from a highlight on a narrated book, from the reader and from the Highlights tab
Barnabasc2d2e196d31c
diff --git a/lib/screens/bookmarks_screen.dart b/lib/screens/bookmarks_screen.dartindex 980c3b49..a3b6de53 100644--- a/lib/screens/bookmarks_screen.dart+++ b/lib/screens/bookmarks_screen.dart@@ -19,6 +19,7 @@ import '../widgets/card_buttons.dart';import '../services/download_service.dart';import '../services/ebook_annotation_service.dart';import '../services/highlight_sync.dart';+import '../services/narration_service.dart';import '../utils/episode_key.dart';import '../widgets/absorb_page_header.dart';import '../widgets/adaptive_modal.dart';@@ -663,6 +664,9 @@ class _BookmarksScreenState extends State<BookmarksScreen>final l = AppLocalizations.of(context)!;final cs = Theme.of(context).colorScheme;final tt = Theme.of(context).textTheme;+ // A book whose EPUB reads itself aloud can play from the highlight.+ final narrated = await NarrationService.instance.knownNarrated(itemId) == true;+ if (!mounted) return;final action = await showAdaptiveActionMenu<String>(context: context,showDragHandle: true,@@ -682,6 +686,12 @@ class _BookmarksScreenState extends State<BookmarksScreen>style: tt.bodyMedium?.copyWith(color: cs.onSurfaceVariant),),),+ if (narrated)+ ListTile(+ leading: Icon(Icons.play_arrow_rounded, color: cs.onSurfaceVariant),+ title: Text(l.narrationPlayFromHere),+ onTap: () => Navigator.pop(ctx, 'play'),+ ),ListTile(leading: Icon(Icons.ios_share_rounded, color: cs.onSurfaceVariant),title: Text(l.quoteShareTitle),@@ -706,7 +716,12 @@ class _BookmarksScreenState extends State<BookmarksScreen>),);if (action == null || !mounted) return;- if (action == 'share') {+ if (action == 'play') {+ await openHighlightInReader(context,+ itemId: itemId, cfi: highlight.cfi, title: _resolveTitle(itemId),+ playNarration: true);+ if (mounted) await _loadHighlights();+ } else if (action == 'share') {await _shareHighlight(itemId, highlight);} else if (action == 'open') {await _openHighlight(itemId, highlight);diff --git a/lib/widgets/ebook_reader_view.dart b/lib/widgets/ebook_reader_view.dartindex 8d493b1a..044cf935 100644--- a/lib/widgets/ebook_reader_view.dart+++ b/lib/widgets/ebook_reader_view.dart@@ -115,6 +115,9 @@ class EbookReaderView extends StatefulWidget {/// Turn read along on as soon as the book is displayed, for the card's/// Read along button.final bool startReadAlong;+ /// Start the narration from [openAtCfi] once the book is displayed, for+ /// Play from here on a highlight outside the reader.+ final bool playFromOpenCfi;const EbookReaderView({super.key,@@ -127,6 +130,7 @@ class EbookReaderView extends StatefulWidget {this.findPositionSeconds,this.openAtAudioSeconds,this.startReadAlong = false,+ this.playFromOpenCfi = false,});@override@@ -235,6 +239,7 @@ class EbookReaderViewState extends State<EbookReaderView> with WidgetsBindingObs// Read along: follow the audiobook by coloring the words being spoken.bool _readAlongOn = false;bool _didAutoReadAlong = false;+ bool _didPlayFromOpenCfi = false;// Backgrounding stops read along; this brings it back on return.bool _readAlongResume = false;// Catch up offers: each direction is offered once per visit.@@ -2146,9 +2151,14 @@ class EbookReaderViewState extends State<EbookReaderView> with WidgetsBindingObs_shareHighlight(annotation, onThisPage: true);},),+ // A narrated book plays from the highlight outright, the same+ // button the selection toolbar shows; the search is for books+ // whose audio has to be matched to the text first.ListTile(- leading: Icon(Icons.headphones_rounded, color: cs.onSurfaceVariant),- title: Text(l.findInAudiobook),+ leading: Icon(+ _useNarration ? Icons.play_arrow_rounded : Icons.headphones_rounded,+ color: cs.onSurfaceVariant),+ title: Text(_useNarration ? l.narrationPlayFromHere : l.findInAudiobook),onTap: () {Navigator.pop(ctx);_findInAudiobookFromSelection(@@ -7409,6 +7419,19 @@ class EbookReaderViewState extends State<EbookReaderView> with WidgetsBindingObsif (mounted && !_readAlongOn) _toggleReadAlong();});}+ final playAt = widget.openAtCfi;+ if (widget.playFromOpenCfi && playAt != null && !_didPlayFromOpenCfi) {+ _didPlayFromOpenCfi = true;+ // Once the load rescue has settled on the highlight and the+ // narration lookup has answered.+ Future.delayed(const Duration(milliseconds: 1200), () async {+ if (!mounted) return;+ await _narrationLookup;+ if (!mounted || !_useNarration) return;+ await _findInAudiobookFromSelection(+ cfiOverride: playAt, textOverride: '', flashPassage: false);+ });+ }unawaited(_narrationOpenAtAudio());if (!_didScheduleCatchUp) {_didScheduleCatchUp = true;diff --git a/lib/widgets/ebook_router.dart b/lib/widgets/ebook_router.dartindex d3dc2f95..4263e4a4 100644--- a/lib/widgets/ebook_router.dart+++ b/lib/widgets/ebook_router.dart@@ -39,6 +39,7 @@ Future<void> openHighlightInReader(required String itemId,required String cfi,String? title,+ bool playNarration = false,}) async {final l = AppLocalizations.of(context)!;final api = context.read<AuthProvider>().apiService;@@ -67,6 +68,7 @@ Future<void> openHighlightInReader(title: title ?? '',ebookFile: ebookFile,openAtCfi: cfi,+ playFromOpenCfi: playNarration,);}@@ -86,6 +88,7 @@ Future<void> openEbookReader(double? findPositionSeconds,double? openAtAudioSeconds,bool startReadAlong = false,+ bool playFromOpenCfi = false,}) async {final ext = ebookExt(ebookFile);final Widget viewer;@@ -98,7 +101,7 @@ Future<void> openEbookReader(itemId: itemId, title: title, ebookFile: file, openAtCfi: openAtCfi,findText: findText, findChapterHint: findChapterHint,findPositionSeconds: findPositionSeconds, openAtAudioSeconds: openAtAudioSeconds,- startReadAlong: startReadAlong),+ startReadAlong: startReadAlong, playFromOpenCfi: playFromOpenCfi),);} else if (comicEbookFormats.contains(ext)) {viewer = ComicReaderView(itemId: itemId, title: title, ebookFile: ebookFile);