mirror of
https://github.com/readest/readest.git
synced 2026-12-02 09:00:04 +00:00
* fix(android): recover missed narration end events When Android reaches the end of recorded narration while the WebView is suspended, its native ended event may not reach JavaScript. Treat the native no-current-item position as the same terminal event and deduplicate a delayed native callback so the controller can advance. Regression test: recovers an ended event missed while the WebView was suspended failed on upstream main with expected one call, received zero; it now passes. Checks: 78 focused narration tests passed; pnpm lint passed (one existing informational diagnostic); full suite reached 14,438 passed and 43 skipped, with one unrelated tts-paragraph-boundary Windows timeout that also repeats alone. The four initial PDF failures were corrected by restoring the worktree vendor assets and all four reruns passed. Reported by kelvinalfaro on GitHub in #7193. * fix(android): queue next narration file while locked * test(tts): preserve desktop media overlay capabilities * fix(android): rework the locked-screen narration handover The queued handover lost what it was meant to keep. The plugin's new load fields never reached JS (the Rust PlayoutControlResponse carries only `session`), so after a handover every block ended after one poll. On wake the next section sought back to 0 s and replayed audio heard under lock, and stanzas of the old file still behind were sought inside the new one. - The playlist follows rules that depend only on the order of loads and queues: `load` jumps to a file already in the playlist and drops the ones before it, `queue` keeps only the file it follows. JS mirrors them without any new response fields, and a rollover racing a load cannot split them. - When JS runs again, `NativeNarrationPlayer.sync()` reads where the player got to: clips of a file it played past are skipped, the next section joins the rolled-over file where it is, and a lost rollover or end of file is found from the position. - An `ended` that lands while no clip wait is listening still ends the block: this was the "playing" in silence, with Pause and Play doing nothing, after unlock. - Only while a section's last file plays is the next one queued, and never for multi-track audiobooks or on iOS. A queueing failure no longer drops the next section's opening preload. Staged copies are kept only while in the playlist. Verified on the Android emulator (API 35) with a six-poem narrated EPUB, freezing the WebView renderer (kill -STOP) to model the suspended WebView: - main: audio stopped at the end of poem 1; after the thaw stanzas 2-3 were replayed, then it stuck "playing" in silence, and Pause/Play did not resume. - this change, frozen 60 s: ExoPlayer rolled into poem 2; after the thaw poem 2 was passed over and poem 3 played. Frozen 10 s / awake 1 s for 90 s: one unbroken audio track through all six poems. Screen on: one continuous track, the highlight following; pause/resume and previous sentence across a boundary work. Not verified on a physical device or on iOS. Tests: media-overlay-android-handover.test.ts. Without each part of the change its tests fail on assertions: no rollover handling ("expected [ 'load poem2.mp3' ] to deeply equal []", "expected [ 'seek poem2.mp3 6s' ] to deeply equal []"), no end-of-file position read ("expected 'stuck' to deeply equal [ { code: 'end' } ]"), no ended check in the clip wait (same), no guard on a late rollover event ("expected [ { code: 'end' } ] to be 'stuck'"). The two ended tests fail the same way on main. Reported by kelvinalfaro on GitHub (#7193). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(android): keep offering the next narration file until it is queued The next section's file was offered to the client once per section, when the cached opening was built. In a section recorded across several files that offer comes while an earlier file plays, so it was declined and never made again: with the WebView suspended, narration stopped at the section's end. - The loaded next section is kept with the cached opening and offered on every preload; an offer for a file already queued does no work. - A section's own next file is queued too, while the one before it plays, so a boundary inside a section crosses without JS as well. Verified on the Android emulator with a narrated EPUB whose third stanza of each poem is its own file, freezing the WebView renderer: - 73590cbd0: frozen after the poem's last file started, it stopped at that file's end (poem 2 never queued); frozen inside the first file, it stopped at that file's end. - this change: the first case rolled on into poem 2, then after the thaw skipped the stanzas heard and rolled into poem 3; the second rolled into the third-stanza file. Tests: "offers the next section to the client on every preload, loading it once" fails without the change with "expected preloadSection to be called 2 times, but got 1 times"; "an offer repeated on every preload queues the file once" with "expected 4 to be 2"; "queues the section's own next file while an earlier one plays" with "expected [ 'load poem1.mp3' ] to include 'queue poem1-c.mp3'". Raised by CodeRabbit's review of 73590cbd0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(android): queue the next narrated section, and drop a queue that went stale - The file offered for queueing was the adjacent section's, so a section with no recording between two narrated ones (an interlude, a page the narrator skips) left nothing queued, though playback steps over it. The next narrated section is now found the way the section change finds it. The text opening still comes from the adjacent section. - A queue whose file was still resolving when another file loaded could land after the new file and play the old section's audio. The player now checks, with nothing awaited before the command, that the file the queued one follows is still the one playing. Verified on the Android emulator with a narrated EPUB that puts an unnarrated interlude page after each poem, freezing the WebView renderer 8 s into poem 1: - 9ed692479: poem 1 ended and the playlist ended with it; silent until the thaw. - this change: poem 1 rolled on into poem 2 across the interlude; after the thaw, poem 2's stanzas were passed over and poem 3 played. The split-file book from 9ed692479 behaves as before. The stale-queue race is covered by the unit test only. Tests: "offers the next narrated section, stepping over one without a recording" fails without the change with "expected preloadSection to be called once, but got 0 times"; "a queue still resolving when another file loads is dropped" with "expected [ 'queue poem2.mp3' ] to deeply equal []". Raised by CodeRabbit's review of 9ed692479. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(tts): reconcile Android narration ends and late rollovers by position Two follow-ups from CodeRabbit's review of b18827d30, both about matching JS to where ExoPlayer really is after the WebView slept. - When both the loaded file and the queued one finished under lock and every event was lost, the position read said only index -1, so JS still thought the first file was current and replayed the queued one. The plugin now keeps the item the playlist ended on and reports it as endedIndex once nothing is current; sync() rolls to it. - A late item-ended event named an index that a later queue had reused: after a position read found A -> B and C was queued, A's event (index 0) rolled JS on to C and ended B's stanza while B was still playing. The event now only prompts a position read, which rolls only when the player really moved. Verified: - "after a lock longer than the queued file, with every event lost" fails without the endedIndex change (expected 'stuck' not to be 'stuck'). - "a late rollover event from before the next queue does not end the file playing" fails without the event change (expected [{ code: 'end' }] to be 'stuck'). Both pass with it; src/__tests__/services/tts 920 passed. - pnpm lint, format:check, fmt:check, clippy:check, test:rust (201 passed). - Android emulator (API 35, x86_64 debug APK), split-narration book: screen on, one ExoPlayer track across four sections with the highlight following; renderer frozen 50 s and 12 s, narration continued into the next section on thaw with nothing replayed. The lost-event cases can't be produced there (SIGSTOP queues events, it doesn't drop them), so they are covered by the unit tests only. Reported by kelvinalfaro on GitHub (#7193). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(tts): drop narration end signals that belong to a replaced file Follow-ups from CodeRabbit's review of ce477e976. Since an end of file can now be found by polling, the `ended` event and a slow position read can both arrive after JS has moved on and loaded the next file, and each ended that new file's wait at once. - An `ended` event now only ends playback when a position read confirms the player is still at an end (both plugins clear the current item before they send it, iOS included). - A position read that overlapped a load is dropped: the player counts loads, and sync() ignores a reply when the count changed while it waited. The third finding, a queue that lands after the playlist ended, needed no change: the next run sees the player still on the old file and loads the queued one, which the plugin jumps to. A test now covers that. Verified: - "a late ended event does not end the file loaded since" and "a position read taken before a load does not end the file loaded" fail without the change (expected [{ code: 'end' }] to be 'stuck'); they pass with it. "a file queued after the playlist ended is loaded, not waited on" passes before and after. - src/__tests__/services/tts: 924 passed. pnpm lint, format:check. - Android emulator (API 35, x86_64 debug APK), split-narration book: played to the end of the book with the screen on, and TTS stopped 0.2 s after ExoPlayer ended. Renderer frozen 12 s: continued into the next section on the thaw. iOS not run: its plugin clears the index before `ended`, read from NativeTTSPlugin.swift only. Reported by kelvinalfaro on GitHub (#7193). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Kel <1563599+kelvinalfaro@users.noreply.github.com> Co-authored-by: Huang Xin <chrox.huang@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| src | ||
| .gitignore | ||
| build.gradle.kts | ||
| proguard-rules.pro | ||
| settings.gradle | ||