From 4591a82516906da1870b6fb4eb8d91396fb7bfb6 Mon Sep 17 00:00:00 2001 From: KodeStar Date: Sun, 22 Nov 2026 21:36:02 +0000 Subject: [PATCH 1/4] Document one rule for chapters that share a start Covers the FE-TIES player change: the chapter of the playing file is named everywhere when chapter starts tie, a zero-length marker at a start does not win, Next and Previous step in file order on the phone, web and both watches (shared timeline-ties vectors), skips and seeks stay in the playing file, and the sleep sheet offers no stop-after rows in a chapter of unknown length. --- docs-developers/frontend/apple-watch.md | 19 +++++- docs-developers/frontend/book-page.md | 39 ++++++++----- docs-developers/frontend/playback.md | 78 +++++++++++++------------ docs-developers/frontend/player-ui.md | 36 +++++++++--- docs-developers/frontend/wear-os.md | 15 +++++ docs-users/listening/sleep-timer.md | 4 +- 6 files changed, 125 insertions(+), 66 deletions(-) diff --git a/docs-developers/frontend/apple-watch.md b/docs-developers/frontend/apple-watch.md index a201fe16..f5b4783f 100644 --- a/docs-developers/frontend/apple-watch.md +++ b/docs-developers/frontend/apple-watch.md @@ -63,7 +63,7 @@ these changes both sides, with tests on both: | The player | The watch | |---|---| -| `book-queue.ts` | `Core/Timeline.swift`; whole-book chapter moves in `Core/PlayerRules.swift` | +| `book-queue.ts` and `transport.ts` | `Core/Timeline.swift` resolves file places and `ChapterNav` in `Core/PlayerRules.swift` selects and steps between chapters | | `listening-sync.ts`, `listening-outbox.ts` | `Core/SpanRecorder.swift`, `Core/Outbox.swift` | | `progress-sync.ts`, `place-reconcile.ts` | `Core/AckAndOffer.swift` | | `server-address.ts`, `pairingFallback` | `Core/AddressPicker.swift` | @@ -98,6 +98,14 @@ seek bar). Away from 1x, one more line gives the wall-clock time left in the pho ## Playing and syncing +Now Playing passes the playing file to `ChapterNav.index` to find its chapter. +When files share a start, `ChapterNav.step` takes Previous and Next in file order +from the current file and seconds into it. With every file length known, it uses +whole-book seconds. A chapter tap or a step between tied files gives +`WatchAudioEngine.seek` the chapter's file path and in-file start. +`Timeline.resumePlace` resolves those to a queue index and seconds. For a skip +or scrub given only book seconds, it prefers the playing file among tied files. + **Starting to play** (`Playback/WatchAudioEngine.swift`): - **A refused start.** A start the player refused before its audio moved is often the system @@ -158,8 +166,13 @@ npm run test:watch # swift test on watch-core/; skips, and passes, without sw ``` `.github/workflows/watch.yml` runs it on a macOS runner when `targets/watch/**`, `watch-core/**` -or the script change, since the Linux `ci` job has no Swift toolchain. The Swift tests carry the -TS test vectors. They cover the timeline, spans, the outbox, acks and offers, addresses, message +or the script change, since the Linux `ci` job has no Swift toolchain. +`TimelineTests`, the phone's Jest tests and Wear's JUnit tests all read +`watch-core/Tests/WatchCoreTests/Fixtures/timeline-ties.json`. Its cases check +which file and chapter a place selects, ties with a zero-length marker, and the +file and seconds reached by Previous and Next. + +The Swift tests also cover spans, the outbox, acks and offers, addresses, message decoding and encoding, the rendition plan, held books, the `remove` decision, `StatePublication`, the download percent (`DownloadProgress`), a refused start (`StartRefusal`), `AccountRules` and `JSONFile.load`. diff --git a/docs-developers/frontend/book-page.md b/docs-developers/frontend/book-page.md index d88b8a8c..667673ad 100644 --- a/docs-developers/frontend/book-page.md +++ b/docs-developers/frontend/book-page.md @@ -121,13 +121,16 @@ Both ways to play go through the app's one play path, `usePlayBook` - The primary calls it with `{ toggle: true }`. A loaded book pauses or plays in place on every layout; it never restarts. -- A chapter row, a timeline tap or a step key calls it with `{ at: jump }`. A `Jump` is - a `BookPlace`, `{ position?, track? }`, with a track for a file of unknown length. +- A chapter row calls it with `{ at: jump }`. A `Jump` is a `BookPlace`. For a + chapter it carries the corrected whole-book `position` and, when known, + `file: { path, pos }` with the library-relative path and the chapter's start in + that file. A file row carries `track`. A timeline tap supplies whole-book seconds. - On a phone it opens the full player there, unless the player is already on top. The route applies the jump once, also to the loaded book. - - On a tablet or desktop it jumps the loaded book there (`seekBook`, or - `goToTrack`) and plays on, or starts this book there in place - (`startBookInPlace`). + - On a tablet or desktop it jumps the loaded book there or starts it in place + (`startBookInPlace`). Both paths resolve a chapter's file against the actual + queue. A partly downloaded book can keep files in a different order. If the + file is missing, playback uses the whole-book position. `usePlayBook` rejects when the book can't start. The error is a `PlaybackStartError` when the engine couldn't start it (see @@ -348,16 +351,24 @@ chapters have the same shape either way. `useBookAnnotations` (`pinsOf`): - While the book is loaded, its place follows the player - (`timelinePosition(selectBookPosition)`), and a tap or drag `seekBook`s. + (`timelinePosition(selectBookPosition)`), and a tap or drag calls `seekBook`. - Otherwise it draws the saved place, and a tap jumps through `usePlayBook`. -- A step key goes to the next chapter start or back to the start of the current one - (`nextSegmentStart`, `previousSegmentStart`, the transport's own rules). - -`scrubTarget` keeps a tap from landing in the last 30 s. The current row is -`rowAt(rows, position)`; the page passes it in, and every row counts as heard once the -book is finished. A row is memoised on its few values: its state and the bookmark -glyph. A bookmark inside the book marks the row `rowAt` puts it in. So a moving place -redraws only the rows that change. +- `scrubTarget` keeps both kinds of tap short of the book's end. +- A step key on a loaded book uses the player's `stepSegment`, which can step + between files at the same start. Before the book loads, the keys use whole-book + seconds from the saved place (`nextSegmentStart` and `previousSegmentStart`). + +`rowAt(rows, position, file)` matches the playing chapter by file path and in-file +start, so its row can differ from its index in a partial queue. Before playback, +it uses the saved file and seconds when available. With only book seconds it picks +the latest start reached and breaks ties in file order. In one file a chapter +with length takes precedence over a zero-length marker at the same start. + +The timeline uses the current row at the playhead and `rowAt(rows, seconds)` for +other hover positions. It uses a row as the current timeline segment only when +every row has a known start. A bookmark marks the row `rowAt` finds for its book +position. Each row is memoised on its state and bookmark glyph, and all rows +count as heard once the book is finished. ### The Details tab diff --git a/docs-developers/frontend/playback.md b/docs-developers/frontend/playback.md index b3c293c8..f3aea354 100644 --- a/docs-developers/frontend/playback.md +++ b/docs-developers/frontend/playback.md @@ -538,11 +538,11 @@ track is exactly what it always was. A local file is never transcoded. Other queue math that lives here: -- **`chapterBookOffset`** recomputes every chapter's whole-book offset from the - client's own file durations plus the in-file `start`. It locates the file **by - `file_path` first**, with a bounds-checked `file_index` fallback. It deliberately - ignores the server's `book_offset`, which comes back 0 for every chapter on some - on-demand-indexed books. That made chapter detection resolve to the last chapter. +- **`buildBookQueue`** resolves each chapter's file by `file_path`, falling back + to a valid `file_index`. It records the resolved path and index and adds the + file's offset to the chapter's in-file start. The screens use the same sum + (`chapterBookOffset`). For some books indexed on demand, the server reports + `book_offset` as 0 for every chapter. - **`buildChapterClips(specs, chapters)`** produces the native clip list. Android plays the clips as items; iOS uses them for its chapter lock screen. - Each chapter becomes one clip mapped to `(fileIndex, [startInFile, @@ -565,36 +565,36 @@ Other queue math that lives here: - **`locate(offsets, bookPosition, prefer?)`** and **`toBookPosition(offsets, index, positionInTrack)`** convert between the whole-book timeline and per-track coordinates. -- **`chapterAt(chapters, bookPosition, playing?)`** finds the active chapter by - `book_offset`. -- **Files that share an offset.** A file of unknown length (a server with no - prober, or a VBR MP3 with no header, reports 0) gives the next file the same - offset. `locate` resolves such a tie to the **first** of the tied files, since the - length is unknown rather than zero, so a book starts in its first file. A caller - that knows the file the place is in (the playing one, a chapter's) passes it as - `prefer`, and among the tied files that one wins. `chapterAt` does the same for - chapters that share a start in different files: the first file's wins, unless - `playing` names another tied file, so the player names the chapter of the file - it is in. Within one file, a tie is a chapter of no length before another, and the - later one is the chapter playing. The companion's chapter list seeks to a chapter - in its own file (`seekBook(offset, trackIndexById(...))`). +- **Files that share an offset.** A file of unknown length contributes zero seconds + to the next file's offset. Given only whole-book seconds, `locate` picks the + first file at the latest offset reached. For a skip, scrub or seek, `seekBook` + passes the playing file as `prefer`. For a book with file offsets of 0, 60 and + 60 s, a skip back to 65 s stays in file three while it plays. A skip back to + 55 s lands in file one. +- **Chapter names.** `chapterAt(chapters, bookPosition, playing?)` looks for the + latest chapter start reached in the playing file. If none qualifies, it checks + all files. `indexAtOffset` checks every start because ties can occur on either + side of a later start. At equal starts, `tiedMarkerWins` prefers the first file + in play order. Within one file, a chapter with length takes precedence over a + zero-length marker. Otherwise the first in chapter list order wins. A lone + zero-length marker still names its chapter. +- **Chapter taps and saved places.** A chapter tap carries the file's path and the + seconds into it, as can a saved place. `filePlaceIn` looks up the path in the + queue that will play, which can have a different file order after a partial + download. If the named file is missing, `locateBookPlace` uses the whole-book + position. The companion's chapter list calls + `seekBook(c.book_offset, { path: c.file_path, pos: c.start })`. - **A file's length** as the player reads it is `fileDurationOf(queue, index, engine)`: the engine's, unless the server measured the file and the engine's is unknown or more than `FINISHED_TOLERANCE` (5 s) shorter, then the server's. The snapshot's `duration`, the seek clamp and the time left in the file use it. `shortOfFileEnd` and `endsShortOfBook` feed the engine fault check ([An engine that runs off a short file](#an-engine-that-runs-off-a-short-file)). -- **`chapterCountdowns`** feeds the sleep sheet's "Or stop after" rows, with - wall-clock times scaled by the playback rate (`rate.ts` `wallClockSeconds`). - **`nextChapterEnd`** answers the sleep timer's question "where does the next - worthwhile chapter end?". Both use the same `chapterEndPosition`, so the list the - listener picks from and the boundary a shake retargets cannot disagree. - - Neither assumes the chapters ascend by position. `chapterBookOffset`'s fallback - for an out-of-range `file_index` degrades to 0 preceding files, so stale or - duplicated metadata yields ends that are not monotonic. `chapterCountdowns` - therefore locates the current chapter with `chapterAt`, and `nextChapterEnd` takes - the **nearest** qualifying end rather than the first qualifying array element. +- **`chapterCountdowns`** starts the sleep sheet's list at the chapter found by + `chapterAt` for the playing file. It scales the time until each end by the + playback rate. The End of chapter tile and a shake use `nextChapterEnd`, which + scans for the nearest qualifying end in whole-book seconds. Both functions + calculate chapter ends with `chapterEndPosition`. `total` is the largest of the book's reported duration, the summed file durations and the furthest chapter end. Metadata with `duration: 0` then degrades instead of @@ -607,8 +607,8 @@ per-track, and the selectors map it to the whole-book timeline: - `selectBookPosition` is `toBookPosition(queue.offsets, snapshot.trackIndex, snapshot.position)`. -- `selectCurrentChapter` overlays `queue.chapters` on that position by - `book_offset`. The full player's seek bar is **chapter-relative**. +- `selectCurrentChapter` passes that position and the playing file's path to + `chapterAt`. The full player's seek bar is **chapter-relative**. The actions are `playBook`, `toggle`, `pause`, `retry`, `seekBook`, `seekInTrack`, `goToTrack`, `skipSeconds`, `setRate` and `stop`. `seekInTrack` and `goToTrack` @@ -819,19 +819,21 @@ It keeps the newest record by `updated_at`. Unlike the replay queue, it is **nev pruned on sync**. It exists so a flaky resume fetch can't lose the position, after a beta report of a book that "restarted from the beginning". -**On the way out: the `resumeFloor` save guard (`store.ts`).** The store keeps the -whole-book position it actually resumed from as a running high-water mark. +**On the way out: the `resumeFloor` save guard (`store.ts`).** The floor starts at +the resume position and advances as the player saves progress. The store keeps +both the whole-book seconds and the track that set the floor. `persist` refuses to save a position more than `SLIP_TOLERANCE` (60 s) *below* that floor. -- Only a deliberate seek or jump by the listener lowers the floor: `lowerFloorTo` - in `seekBook`, `seekInTrack` and `goToTrack`, and a native `onRemoteMove`, which - is the listener's own move made outside the app. +- A deliberate seek or jump can lower the floor through `lowerFloorTo`, including + a native `onRemoteMove`. A natural advance to a later file at the same offset + can also lower it. The next file can report fewer whole-book seconds even though + the listener has moved forward. - The server is last-write-wins. Without the guard, a restart at 0 that slipped through with a fresh timestamp would overwrite real progress for good. The guard makes that write impossible. -- `retry()` also reloads at `max(resumeFloor, currentPosition)`, so a transient 0 - in the snapshot can't be loaded again. +- When Retry needs the floor, `reloadPlace` uses the file that set it. This keeps + a low engine reading from restarting a different file at the same book second. ### An engine that runs off a short file diff --git a/docs-developers/frontend/player-ui.md b/docs-developers/frontend/player-ui.md index dc06506f..9e0dc73b 100644 --- a/docs-developers/frontend/player-ui.md +++ b/docs-developers/frontend/player-ui.md @@ -274,9 +274,6 @@ have carried the listener in the wall-clock time between them. - a move forward beyond that by more than the threshold, or backward by more than the threshold, is a jump. -One rule covers every source, which is why the store isn't touched. A recording site -in `seekBook` would miss every jump the engine makes on the OS's behalf. - What must **not** read as a jump, and why it doesn't: - **Loading or resuming a book**, and a book change: the baseline drops when @@ -284,7 +281,10 @@ What must **not** read as a jump, and why it doesn't: state) is skipped. For a short settle window after the first fresh sample, the samples only move the baseline. - **Retry, reloads and buffering**: only `playing` and `paused` are sampled. -- **The downloads hot-swap**: same book, same position. +- **A download swap or Retry** can give the same book a new file order or new + offsets. Either change makes old whole-book seconds unreliable. `startJumpUndo` + drops the previous sample and clears any visible undo chip. A replacement queue + with the same files in the same order and at the same offsets keeps the chip. - **The app coming back after iOS suspended JS**: a heartbeat runs only while the app is not active and a book is loaded. A stalled heartbeat marks the return `unobserved`. Forward movement up to the allowance is then accepted even from a @@ -587,9 +587,11 @@ content with its own scroller. Children mount only while the sheet is open. - **Speed** is `speed-model.ts`: the grid, the presets, stepping and the sheet's own range (`SPEED_MIN`/`SPEED_MAX`). The range is the same 0.5-2 that `clampRate` in `rate.ts` enforces in the store. -- **Sleep** is `sleep-sheet-model.ts`: the presets, the "Or stop after" rows and the - notice. The End of chapter tile's target comes from `chapterTimerTarget` - (`src/playback/sleep-timer.ts`), the rule the timer itself arms. +- **Sleep** uses `stopAfterRows` in `sleep-sheet-model.ts` for "Or stop after". + The playing file identifies the current chapter when starts tie. If that chapter + has no known length, the sheet hides the whole list. A later chapter's end time + could still fall inside the playing file. The End of chapter tile gets its own + target from `chapterTimerTarget` in `src/playback/sleep-timer.ts`. Picking a timer records a touch (`noteInteraction`) and closes the sheet. The sleep readouts (`useSleepPill`, `useSleepCountdown`) read the phase, the countdown and the @@ -645,6 +647,12 @@ The whole-book timeline is `book-timeline.tsx` with the pure - **Runs.** Chapters are merged into runs like the Now card's `scaleRuns`. Each run is placed by time with `runBox`, the one mapping that the playhead, taps and pins use. +- **Chapter names.** At the playhead, `BookTimeline` uses the current chapter or + row supplied by its caller for the hover tip and slider value text. Elsewhere it + calls `chapterAtSecond`. The player uses `chapterAt` and keeps the playing + chapter's name when the hovered chapter shares its start. The book page uses + `rowAt`. Both lookups prefer the chapter with length over a zero-length marker + at the same start in the same file. - **Pins.** Bookmark and note pins come from `usePlayingPins`, the playing book's case of `useBookAnnotations`. That hook reads ANY book's bookmarks and notes, and their `pins`, through its own connection. It never throws when the connection is @@ -659,14 +667,24 @@ The whole-book timeline is `book-timeline.tsx` with the pure The book page draws the same `BookTimeline` for any book ([The book page](book-page.md#the-chapters-tab)). +Home's Now card uses `tiedChapterIndexAt` for both the chapter label and the +highlight on its scale. It uses the playing file and seconds into it for a live +place, or the saved file and seconds when showing saved progress. + ### Rings, the transport and titles - **Rings** (`src/components/ui/progress-ring.tsx`): `ProgressRing` (a fraction the caller ticks) and `CountdownRing` (empties by itself, on the UI thread). Both are transform-only. - **The transport cluster** (`transport-controls.tsx`) comes in three sizes. - Previous and next read the live position at press time through `stepSegment` - (`transport.ts`), which steps by chapters, else by files. + Previous and Next read the live file and position through `stepSegment` in + `transport.ts`. When files share a start, `stepInFileOrder` orders chapters by + file and then by seconds into that file. It seeks by file path and in-file + start, so Next reaches the next file's chapter even at the same book time. + Previous restarts the chapter after three seconds and goes to the preceding + chapter within those first three seconds. + With distinct file starts the controls use whole-book seconds. They step by + file if the queue has no chapters or no usable book duration. - **`prettify-title.ts` cleans filename-shaped labels for display.** Audiobook "chapter" labels are often just the audio *filename* (`01_the_hobbit_ch1.mp3`). `prettifyChapterTitle` strips a recognised extension, turns underscores into diff --git a/docs-developers/frontend/wear-os.md b/docs-developers/frontend/wear-os.md index a4a71d06..029df9dd 100644 --- a/docs-developers/frontend/wear-os.md +++ b/docs-developers/frontend/wear-os.md @@ -157,6 +157,16 @@ per downloaded file. Audio focus and becoming-noisy are handled, with speech att chapters, the skips are 15 and 30 s, and a scrubber is a move. `OngoingNotification` adds the `OngoingActivity` while playing. +Now Playing identifies the chapter with `ChapterNav.index` and the playing file. +When files share a start, `ChapterNav.step` orders chapters by file and in-file +start and gives `PlayerEngine.seek` the target file path and seconds. A chapter +tap supplies the same coordinates. With every file length known, Previous and +Next use whole-book seconds. + +`Timeline.resumePlace` resolves the seek. A timed skip prefers the playing file +among files at the target offset. For a system scrub, `ChapterPlayer.seekTo` +passes the Media3 item index so the engine can seek in that specific file. + **The speaker.** `setSuppressPlaybackOnUnsuitableOutput(true)` holds until the listener confirms the speaker (prefs `player`, `speakerConfirmed`). A play with only the built-in speaker shows the one-time question in `Prompts.kt`. Yes rebuilds the player without suppression and hands it to the @@ -285,6 +295,11 @@ card, the action and the section hide for a kid's or demo account, as on iOS. npm run test:wear # wear-core's JUnit suites (JDK 17 or later); skips, and passes, with no JDK ``` +`TimelineTest` reads `watch-core/Tests/WatchCoreTests/Fixtures/timeline-ties.json`, +the same vectors as the Swift and phone tests. They check the current chapter +with and without a known file, zero-length markers, and the file and seconds +reached by Previous and Next. + After `npx expo prebuild -p android`, from `android/`: ```sh diff --git a/docs-users/listening/sleep-timer.md b/docs-users/listening/sleep-timer.md index 63f676dc..71dee9f9 100644 --- a/docs-users/listening/sleep-timer.md +++ b/docs-users/listening/sleep-timer.md @@ -12,8 +12,8 @@ The sleep timer stops the book for you, so you can fall asleep listening without Pick one of these to start the timer: - **Minutes**: 5, 10, 15, 30, 45 or 60. -- **End of chapter**: stops when the current chapter ends. A book without chapter marks uses its files or its [parts](playback.md#books-without-chapters). -- **Or stop after**: this chapter and up to three more, each with the clock time it ends. +- **End of chapter** uses the book's chapter times. The button shows how long until playback stops. A book without chapter marks uses its files or its [parts](playback.md#books-without-chapters). +- Under **Or stop after**, choose **This chapter** or one of the next three. Each row shows when playback will stop. If the player doesn't know the length of the current chapter, it hides the whole list. The times are real time at your current speed. From 20df5db65b4aec7b4ab2875c7d7a5e27ac0b1e98 Mon Sep 17 00:00:00 2001 From: KodeStar Date: Sun, 22 Nov 2026 21:38:26 +0000 Subject: [PATCH 2/4] Link the tied-start pages to one copy of the tie rule The book page, the timeline and the Wear OS page each restated the chapter tie rule (file order, zero-length markers) in slightly different words. They now link to the player's queue section and the Apple Watch page, keeping only what differs on each surface, and the sleep timer list follows the page's "Name: what it does" pattern again. --- docs-developers/frontend/apple-watch.md | 9 +++++---- docs-developers/frontend/book-page.md | 17 ++++++++--------- docs-developers/frontend/playback.md | 5 ++--- docs-developers/frontend/player-ui.md | 17 ++++++++--------- docs-developers/frontend/wear-os.md | 20 +++++++------------- docs-users/listening/sleep-timer.md | 4 ++-- 6 files changed, 32 insertions(+), 40 deletions(-) diff --git a/docs-developers/frontend/apple-watch.md b/docs-developers/frontend/apple-watch.md index f5b4783f..aa6fd1ba 100644 --- a/docs-developers/frontend/apple-watch.md +++ b/docs-developers/frontend/apple-watch.md @@ -63,7 +63,7 @@ these changes both sides, with tests on both: | The player | The watch | |---|---| -| `book-queue.ts` and `transport.ts` | `Core/Timeline.swift` resolves file places and `ChapterNav` in `Core/PlayerRules.swift` selects and steps between chapters | +| `book-queue.ts`, `transport.ts` | `Core/Timeline.swift` (file places); `ChapterNav` in `Core/PlayerRules.swift` (finding and stepping chapters) | | `listening-sync.ts`, `listening-outbox.ts` | `Core/SpanRecorder.swift`, `Core/Outbox.swift` | | `progress-sync.ts`, `place-reconcile.ts` | `Core/AckAndOffer.swift` | | `server-address.ts`, `pairingFallback` | `Core/AddressPicker.swift` | @@ -99,9 +99,10 @@ seek bar). Away from 1x, one more line gives the wall-clock time left in the pho ## Playing and syncing Now Playing passes the playing file to `ChapterNav.index` to find its chapter. -When files share a start, `ChapterNav.step` takes Previous and Next in file order -from the current file and seconds into it. With every file length known, it uses -whole-book seconds. A chapter tap or a step between tied files gives +When files share a start, `ChapterNav.step` steps Previous and Next in file order, +from the playing file and the seconds into it, as the +[phone's transport](player-ui.md#rings-the-transport-and-titles) does. With every +file length known, it uses whole-book seconds. A chapter tap or a step between tied files gives `WatchAudioEngine.seek` the chapter's file path and in-file start. `Timeline.resumePlace` resolves those to a queue index and seconds. For a skip or scrub given only book seconds, it prefers the playing file among tied files. diff --git a/docs-developers/frontend/book-page.md b/docs-developers/frontend/book-page.md index 667673ad..646729d8 100644 --- a/docs-developers/frontend/book-page.md +++ b/docs-developers/frontend/book-page.md @@ -128,9 +128,8 @@ Both ways to play go through the app's one play path, `usePlayBook` - On a phone it opens the full player there, unless the player is already on top. The route applies the jump once, also to the loaded book. - On a tablet or desktop it jumps the loaded book there or starts it in place - (`startBookInPlace`). Both paths resolve a chapter's file against the actual - queue. A partly downloaded book can keep files in a different order. If the - file is missing, playback uses the whole-book position. + (`startBookInPlace`). Both look the chapter's file up in the queue that plays, + as [the player does](playback.md#building-the-queue-book-queuets). `usePlayBook` rejects when the book can't start. The error is a `PlaybackStartError` when the engine couldn't start it (see @@ -354,15 +353,15 @@ chapters have the same shape either way. (`timelinePosition(selectBookPosition)`), and a tap or drag calls `seekBook`. - Otherwise it draws the saved place, and a tap jumps through `usePlayBook`. - `scrubTarget` keeps both kinds of tap short of the book's end. -- A step key on a loaded book uses the player's `stepSegment`, which can step - between files at the same start. Before the book loads, the keys use whole-book +- A step key on a loaded book uses the player's `stepSegment` + ([the transport](player-ui.md#rings-the-transport-and-titles)). Before the book loads, the keys use whole-book seconds from the saved place (`nextSegmentStart` and `previousSegmentStart`). `rowAt(rows, position, file)` matches the playing chapter by file path and in-file -start, so its row can differ from its index in a partial queue. Before playback, -it uses the saved file and seconds when available. With only book seconds it picks -the latest start reached and breaks ties in file order. In one file a chapter -with length takes precedence over a zero-length marker at the same start. +start, so it finds the right row even when a partial queue orders the files +differently. Before playback, it uses the saved file and seconds when available. +With only book seconds it follows the player's tie rule +([Chapter names](playback.md#building-the-queue-book-queuets)). The timeline uses the current row at the playhead and `rowAt(rows, seconds)` for other hover positions. It uses a row as the current timeline segment only when diff --git a/docs-developers/frontend/playback.md b/docs-developers/frontend/playback.md index f3aea354..df8cb6fd 100644 --- a/docs-developers/frontend/playback.md +++ b/docs-developers/frontend/playback.md @@ -569,12 +569,11 @@ Other queue math that lives here: to the next file's offset. Given only whole-book seconds, `locate` picks the first file at the latest offset reached. For a skip, scrub or seek, `seekBook` passes the playing file as `prefer`. For a book with file offsets of 0, 60 and - 60 s, a skip back to 65 s stays in file three while it plays. A skip back to + 60 s, a skip back to 65 s stays in file three while file three plays. A skip back to 55 s lands in file one. - **Chapter names.** `chapterAt(chapters, bookPosition, playing?)` looks for the latest chapter start reached in the playing file. If none qualifies, it checks - all files. `indexAtOffset` checks every start because ties can occur on either - side of a later start. At equal starts, `tiedMarkerWins` prefers the first file + all files. At equal starts, `tiedMarkerWins` prefers the first file in play order. Within one file, a chapter with length takes precedence over a zero-length marker. Otherwise the first in chapter list order wins. A lone zero-length marker still names its chapter. diff --git a/docs-developers/frontend/player-ui.md b/docs-developers/frontend/player-ui.md index 9e0dc73b..8b3e8fb8 100644 --- a/docs-developers/frontend/player-ui.md +++ b/docs-developers/frontend/player-ui.md @@ -281,10 +281,10 @@ What must **not** read as a jump, and why it doesn't: state) is skipped. For a short settle window after the first fresh sample, the samples only move the baseline. - **Retry, reloads and buffering**: only `playing` and `paused` are sampled. -- **A download swap or Retry** can give the same book a new file order or new - offsets. Either change makes old whole-book seconds unreliable. `startJumpUndo` - drops the previous sample and clears any visible undo chip. A replacement queue - with the same files in the same order and at the same offsets keeps the chip. +- **A download swap or Retry** that changes the file order or the offsets drops + the previous sample and clears any undo chip (`startJumpUndo`), since old + whole-book seconds no longer line up. A queue with the same files, order and + offsets keeps the chip. - **The app coming back after iOS suspended JS**: a heartbeat runs only while the app is not active and a book is loaded. A stalled heartbeat marks the return `unobserved`. Forward movement up to the allowance is then accepted even from a @@ -589,7 +589,7 @@ content with its own scroller. Children mount only while the sheet is open. `rate.ts` enforces in the store. - **Sleep** uses `stopAfterRows` in `sleep-sheet-model.ts` for "Or stop after". The playing file identifies the current chapter when starts tie. If that chapter - has no known length, the sheet hides the whole list. A later chapter's end time + has no known length, the sheet hides the whole list, since a later chapter's end could still fall inside the playing file. The End of chapter tile gets its own target from `chapterTimerTarget` in `src/playback/sleep-timer.ts`. @@ -651,8 +651,7 @@ The whole-book timeline is `book-timeline.tsx` with the pure row supplied by its caller for the hover tip and slider value text. Elsewhere it calls `chapterAtSecond`. The player uses `chapterAt` and keeps the playing chapter's name when the hovered chapter shares its start. The book page uses - `rowAt`. Both lookups prefer the chapter with length over a zero-length marker - at the same start in the same file. + `rowAt`. Both follow the [tie rule](playback.md#building-the-queue-book-queuets). - **Pins.** Bookmark and note pins come from `usePlayingPins`, the playing book's case of `useBookAnnotations`. That hook reads ANY book's bookmarks and notes, and their `pins`, through its own connection. It never throws when the connection is @@ -681,8 +680,8 @@ place, or the saved file and seconds when showing saved progress. `transport.ts`. When files share a start, `stepInFileOrder` orders chapters by file and then by seconds into that file. It seeks by file path and in-file start, so Next reaches the next file's chapter even at the same book time. - Previous restarts the chapter after three seconds and goes to the preceding - chapter within those first three seconds. + Previous restarts the chapter, or goes to the one before within its first three + seconds. With distinct file starts the controls use whole-book seconds. They step by file if the queue has no chapters or no usable book duration. - **`prettify-title.ts` cleans filename-shaped labels for display.** Audiobook diff --git a/docs-developers/frontend/wear-os.md b/docs-developers/frontend/wear-os.md index 029df9dd..7146cea8 100644 --- a/docs-developers/frontend/wear-os.md +++ b/docs-developers/frontend/wear-os.md @@ -157,15 +157,11 @@ per downloaded file. Audio focus and becoming-noisy are handled, with speech att chapters, the skips are 15 and 30 s, and a scrubber is a move. `OngoingNotification` adds the `OngoingActivity` while playing. -Now Playing identifies the chapter with `ChapterNav.index` and the playing file. -When files share a start, `ChapterNav.step` orders chapters by file and in-file -start and gives `PlayerEngine.seek` the target file path and seconds. A chapter -tap supplies the same coordinates. With every file length known, Previous and -Next use whole-book seconds. - -`Timeline.resumePlace` resolves the seek. A timed skip prefers the playing file -among files at the target offset. For a system scrub, `ChapterPlayer.seekTo` -passes the Media3 item index so the engine can seek in that specific file. +Chapters that share a start follow the Apple Watch's rules +([Playing and syncing](apple-watch.md#playing-and-syncing)): `ChapterNav.index`, +`ChapterNav.step` and `Timeline.resumePlace`, with `PlayerEngine.seek` taking the +file path and seconds. For a system scrub, `ChapterPlayer.seekTo` passes the +Media3 item index so the engine seeks in that file. **The speaker.** `setSuppressPlaybackOnUnsuitableOutput(true)` holds until the listener confirms the speaker (prefs `player`, `speakerConfirmed`). A play with only the built-in speaker shows the @@ -295,10 +291,8 @@ card, the action and the section hide for a kid's or demo account, as on iOS. npm run test:wear # wear-core's JUnit suites (JDK 17 or later); skips, and passes, with no JDK ``` -`TimelineTest` reads `watch-core/Tests/WatchCoreTests/Fixtures/timeline-ties.json`, -the same vectors as the Swift and phone tests. They check the current chapter -with and without a known file, zero-length markers, and the file and seconds -reached by Previous and Next. +`TimelineTest` reads the same `timeline-ties.json` vectors as the Swift and phone +tests ([Apple Watch tests](apple-watch.md#tests)). After `npx expo prebuild -p android`, from `android/`: diff --git a/docs-users/listening/sleep-timer.md b/docs-users/listening/sleep-timer.md index 71dee9f9..e453e3ab 100644 --- a/docs-users/listening/sleep-timer.md +++ b/docs-users/listening/sleep-timer.md @@ -12,8 +12,8 @@ The sleep timer stops the book for you, so you can fall asleep listening without Pick one of these to start the timer: - **Minutes**: 5, 10, 15, 30, 45 or 60. -- **End of chapter** uses the book's chapter times. The button shows how long until playback stops. A book without chapter marks uses its files or its [parts](playback.md#books-without-chapters). -- Under **Or stop after**, choose **This chapter** or one of the next three. Each row shows when playback will stop. If the player doesn't know the length of the current chapter, it hides the whole list. +- **End of chapter**: stops at a chapter end from the book's chapter times. The button shows how long until playback stops. A book without chapter marks uses its files or its [parts](playback.md#books-without-chapters). +- **Or stop after**: **This chapter** or one of the next three, each with the time playback stops. The list is hidden when the player doesn't know how long this chapter is. The times are real time at your current speed. From f662f1f8734b5c35f0070628217997f051a52402 Mon Sep 17 00:00:00 2001 From: KodeStar Date: Sun, 22 Nov 2026 21:44:00 +0000 Subject: [PATCH 3/4] Stop promising a chapter timer ends at the chapter's end While a chapter of unknown length plays, the End of chapter timer arms a later chapter's end and can stop mid-file, so the last-30-seconds card no longer says it stops at the chapter's end. "Or stop after" lists this chapter and up to three more, fewer near the end of the book. --- docs-users/listening/sleep-timer.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs-users/listening/sleep-timer.md b/docs-users/listening/sleep-timer.md index e453e3ab..df3bd739 100644 --- a/docs-users/listening/sleep-timer.md +++ b/docs-users/listening/sleep-timer.md @@ -13,7 +13,7 @@ Pick one of these to start the timer: - **Minutes**: 5, 10, 15, 30, 45 or 60. - **End of chapter**: stops at a chapter end from the book's chapter times. The button shows how long until playback stops. A book without chapter marks uses its files or its [parts](playback.md#books-without-chapters). -- **Or stop after**: **This chapter** or one of the next three, each with the time playback stops. The list is hidden when the player doesn't know how long this chapter is. +- **Or stop after**: **This chapter** and up to three more, each with the time playback stops. The list is hidden when the player doesn't know how long this chapter is. The times are real time at your current speed. @@ -34,7 +34,7 @@ In the iPhone app, a running timer also shows on the lock screen as a Live Activ In a timer's last 30 seconds, a card appears with a ring that empties: - A **minutes** timer fades the book out. -- A **chapter** timer plays at full volume and stops at the chapter's end. +- A **chapter** timer plays at full volume until it stops. The card stays for 30 seconds after the book pauses. Until it goes, tap **Keep listening** or [shake your phone](#shake-to-extend) to start the timer again. You get the same minutes again, or one more chapter. From 87919097255c84c45ec5bfcecdff6c2095caae38 Mon Sep 17 00:00:00 2001 From: KodeStar Date: Sun, 22 Nov 2026 21:44:00 +0000 Subject: [PATCH 4/4] Correct the tie-rule details on the player and watch pages The watch steps in file order whenever two files share a start, not whenever a length is unknown, and NowPlayingTimes.of is the caller of ChapterNav.index. Native clips now run in file order, the queue never reads the server's book_offset, and the sleep sheet model still holds the presets and the notice. The sleep timer page notes that the playing file picks the first "Or stop after" row and that the list can be empty. --- docs-developers/frontend/apple-watch.md | 13 +++++++------ docs-developers/frontend/playback.md | 7 +++++-- docs-developers/frontend/player-ui.md | 5 +++-- docs-developers/frontend/sleep-timer.md | 4 +++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/docs-developers/frontend/apple-watch.md b/docs-developers/frontend/apple-watch.md index aa6fd1ba..5758f10f 100644 --- a/docs-developers/frontend/apple-watch.md +++ b/docs-developers/frontend/apple-watch.md @@ -98,12 +98,13 @@ seek bar). Away from 1x, one more line gives the wall-clock time left in the pho ## Playing and syncing -Now Playing passes the playing file to `ChapterNav.index` to find its chapter. +`WatchAudioEngine` passes the playing file to `NowPlayingTimes.of`, which finds +its chapter with `ChapterNav.index`. When files share a start, `ChapterNav.step` steps Previous and Next in file order, from the playing file and the seconds into it, as the -[phone's transport](player-ui.md#rings-the-transport-and-titles) does. With every -file length known, it uses whole-book seconds. A chapter tap or a step between tied files gives -`WatchAudioEngine.seek` the chapter's file path and in-file start. +[phone's transport](player-ui.md#rings-the-transport-and-titles) does. When no two +files share a start, it uses whole-book seconds. A chapter tap or a step between +tied files gives `WatchAudioEngine.seek` the chapter's file path and in-file start. `Timeline.resumePlace` resolves those to a queue index and seconds. For a skip or scrub given only book seconds, it prefers the playing file among tied files. @@ -173,8 +174,8 @@ or the script change, since the Linux `ci` job has no Swift toolchain. which file and chapter a place selects, ties with a zero-length marker, and the file and seconds reached by Previous and Next. -The Swift tests also cover spans, the outbox, acks and offers, addresses, message -decoding and encoding, the rendition plan, held books, the `remove` decision, `StatePublication`, +The other Swift tests carry the TS test vectors too. They cover the rest of the +timeline, spans, the outbox, acks and offers, addresses, message decoding and encoding, the rendition plan, held books, the `remove` decision, `StatePublication`, the download percent (`DownloadProgress`), a refused start (`StartRefusal`), `AccountRules` and `JSONFile.load`. diff --git a/docs-developers/frontend/playback.md b/docs-developers/frontend/playback.md index df8cb6fd..9d03c60c 100644 --- a/docs-developers/frontend/playback.md +++ b/docs-developers/frontend/playback.md @@ -541,12 +541,15 @@ Other queue math that lives here: - **`buildBookQueue`** resolves each chapter's file by `file_path`, falling back to a valid `file_index`. It records the resolved path and index and adds the file's offset to the chapter's in-file start. The screens use the same sum - (`chapterBookOffset`). For some books indexed on demand, the server reports - `book_offset` as 0 for every chapter. + (`chapterBookOffset`). Neither reads the server's `book_offset`, which comes + back as 0 for every chapter on some books indexed on demand. - **`buildChapterClips(specs, chapters)`** produces the native clip list. Android plays the clips as items; iOS uses them for its chapter lock screen. - Each chapter becomes one clip mapped to `(fileIndex, [startInFile, endInFile])`. + - The clips run in file order. A stable sort by file keeps tied markers that + arrive out of file order in the right place, and keeps the chapter order + within each file. - The last chapter in each file clips "to end" (`endInFile = 0`), so an inaccurate final `end` can't cut off the file's tail. - It returns `[]` for **0 or 1 chapters**, and the engine then plays one item per diff --git a/docs-developers/frontend/player-ui.md b/docs-developers/frontend/player-ui.md index 8b3e8fb8..a18b9995 100644 --- a/docs-developers/frontend/player-ui.md +++ b/docs-developers/frontend/player-ui.md @@ -587,8 +587,9 @@ content with its own scroller. Children mount only while the sheet is open. - **Speed** is `speed-model.ts`: the grid, the presets, stepping and the sheet's own range (`SPEED_MIN`/`SPEED_MAX`). The range is the same 0.5-2 that `clampRate` in `rate.ts` enforces in the store. -- **Sleep** uses `stopAfterRows` in `sleep-sheet-model.ts` for "Or stop after". - The playing file identifies the current chapter when starts tie. If that chapter +- **Sleep** is `sleep-sheet-model.ts`: the presets (`SLEEP_MINUTES`), the notice + (`sleepNotice`) and the "Or stop after" rows (`stopAfterRows`). The playing file + identifies the current chapter when starts tie. If that chapter has no known length, the sheet hides the whole list, since a later chapter's end could still fall inside the playing file. The End of chapter tile gets its own target from `chapterTimerTarget` in `src/playback/sleep-timer.ts`. diff --git a/docs-developers/frontend/sleep-timer.md b/docs-developers/frontend/sleep-timer.md index 51b3a1e4..c501e277 100644 --- a/docs-developers/frontend/sleep-timer.md +++ b/docs-developers/frontend/sleep-timer.md @@ -37,7 +37,9 @@ The sleep sheet arms and reads the store in two places: list real chapters only, never the synthetic `virtualChapterInterval` ones. They arm through `startUntilPosition(endPosition, stopAfterLabel(row))`. The first row ("This chapter") uses the chapter's own label (`chapterSleepLabel`), and the - others use `afterChapters`. + others use `afterChapters`. The playing file picks the first row among chapters + that share a start, and the list is empty when that chapter has no length + ([Speed and sleep sheets](player-ui.md#speed-and-sleep-sheets)). - The "End of chapter" tile shows the countdown of `chapterTimerTarget`. The store exports it so the tile and the timer it starts compute one target.