Skip to content

feat(narration): include the physical page in narration audio locators - #380

Open
emmiemmy wants to merge 5 commits into
Notalib:mainfrom
mtmse:feat/audio-physical-page
Open

emmiemmy wants to merge 5 commits into
Notalib:mainfrom
mtmse:feat/audio-physical-page

Conversation

@emmiemmy

@emmiemmy emmiemmy commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Apps could not show the current printed page while a book is read aloud. The page was only worked out by the reader view, from what is visible on screen, so the audio locators never had it. Without a visible reader view there was no page at all.

On Android and iOS, every narrated sentence now gets the page it is on: the latest page break in the pageList at or before it. The audio locator includes it as physicalPage. This works for both Sync Narration and Guided Navigation.

Locations.physicalPage also returned null during normal reading on Android and iOS. The native side sends the page as a physicalPage location, but the getter only read a physicalPage= fragment, which the native side never sends.

Change

  • Android, iOS: when narration starts, withPhysicalPages gives each narrated sentence its page. The audio locator adds it as physicalPage, next to tocHref.
  • Page breaks without a narration cue: found by reading the XHTML file with the existing XhtmlIdTree and checking which page break comes before the text. This is the same approach ADR 0001 uses for ToC entries without a cue. Only files that contain such a page break are read.
  • Dart: Locations.physicalPage reads the physicalPage location, and still reads the old fragment for older saved locators. copyWithPhysicalPageNumber writes to and clears the same location.

Review notes

  • Books where every page break has a narration cue open without reading any extra files. In all the test books with a page list, every page break has a cue, even when its audio is silent.

Verification

  • Android: PhysicalPageTest (11 tests) and all unit tests (162) pass. ktlint and compileDebugKotlin are clean.
  • iOS: PhysicalPageTests (8 tests, one of them loads a small book with a page break without a cue) and all RunnerTests (115) pass. flutter build ios --no-codesign passes.
  • Dart: all unit tests pass (flutter_readium_platform_interface 249, flutter_readium 52), including locations_physical_page_test.dart. bin/format, bin/analyze and bin/check_channel_parity are clean.
  • New integration test narration locators carry the physical page, using 38533_overlay_preview and 38533_guided_navigation_preview. Passes on an Android emulator and an iOS simulator.
  • Full integration suite on the Android emulator: 59 passed, 6 skipped. Timebased playback group on the iOS simulator: 21 passed, 1 skipped.
  • Example app: tested with local copies of a Sync Narration book and a Guided Navigation book, each with all page-break cues and with the cues removed for one chapter. physicalPage changed correctly in all four cases.

Not covered

  • Web. Not part of this PR.
  • No test book has page breaks without a narration cue, so there is no integration test for that case. It is covered by unit tests and was checked by hand. A copy of 38533_overlay_preview without the page-break cue could be added to readium-test-resources if you want one.

🤖 Generated with Claude Code

emmiemmy and others added 5 commits December 1, 2026 09:28
Synchronized narration audio locators now carry `physicalPage` in their
locations on Android and iOS: the label of the latest pageList entry at or
before the narrated text. Apps can show the current printed page and step
to the previous or next page during playback.

Locations.physicalPage now reads that location, with the old
`physicalPage=` fragment as fallback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…e location

The getter reads the physicalPage location first, but the setter only wrote
a physicalPage= fragment, so a new value was hidden by an existing location
and null could not clear it. The setter now sets or removes the location and
drops any legacy fragment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The page only advanced when a narration item was itself a page-list anchor,
so a page break without a narration cue left the following text on the
previous page, or on none. When the overlays are loaded, Android and iOS now
read the element ids of every narrated XHTML file that holds a page-list
entry and give each item the latest page break before it in document order.
Files that cannot be read keep the exact-match behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Opening a publication with a page list read the XHTML of every narrated file
that held a page break, even when every page break had a narration cue and
the cues already gave the page. Only files with a page break that no
narration item points at are now read, so publications whose page breaks
are all cued open without extra XHTML reads. This follows ADR 0001, which
reads XHTML only where cues cannot resolve the answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add an integration test that seeks to cues around the page-3 break in the
Sync Narration and Guided Navigation preview fixtures and checks the
physicalPage of the timebased locator: none before the first page break,
"3" at the break, and "3" carried into the next resource.

goToLocator first publishes the requested locator, so the test waits for
the player's own locator, which has a time fragment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@emmiemmy
emmiemmy marked this pull request as ready for review December 2, 2026 11:15

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant