fix(audio): replace autoStartPending bool with autoStartChapter number

The boolean flag was set by onended before goto() resolved, causing the
still-mounted outgoing chapter's AudioPlayer $effect to fire and call
startPlayback() for the wrong (old) chapter — restarting it from scratch.

Replace with autoStartChapter (number | null): the AudioPlayer only acts
when its own chapter prop === autoStartChapter, so the outgoing component
never matches and the incoming one fires exactly once on mount.
This commit is contained in:
Admin
2026-03-04 18:08:12 +05:00
parent 80da1bb3e2
commit 0eee2eedf3
3 changed files with 17 additions and 8 deletions

View File

@@ -70,9 +70,11 @@
});
// Auto-start: if the layout navigated here via auto-next, kick off playback.
// We match against the chapter prop so the outgoing chapter's AudioPlayer
// (still mounted during the brief navigation window) never reacts to this.
$effect(() => {
if (audioStore.autoStartPending) {
audioStore.autoStartPending = false;
if (audioStore.autoStartChapter === chapter) {
audioStore.autoStartChapter = null;
startPlayback();
}
});