fix(audio): fix auto-next reliability issues
- Clear autoStartPending if goto() fails to avoid spurious auto-starts on future navigations - Clear audioStore.nextChapter on AudioPlayer unmount so a stale chapter can't trigger navigation after leaving a chapter page - Remove redundant nextChapter write in startPlayback() — the already keeps it in sync
This commit is contained in:
@@ -46,8 +46,13 @@
|
|||||||
|
|
||||||
// Keep nextChapter in the store so the layout's onended can navigate.
|
// Keep nextChapter in the store so the layout's onended can navigate.
|
||||||
// Run as an effect so it stays in sync if the prop ever changes.
|
// Run as an effect so it stays in sync if the prop ever changes.
|
||||||
|
// On unmount, clear it so a stale value can't trigger navigation after
|
||||||
|
// the user leaves the chapter page.
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
audioStore.nextChapter = nextChapter ?? null;
|
audioStore.nextChapter = nextChapter ?? null;
|
||||||
|
return () => {
|
||||||
|
audioStore.nextChapter = null;
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Auto-start: if the layout navigated here via auto-next, kick off playback.
|
// Auto-start: if the layout navigated here via auto-next, kick off playback.
|
||||||
@@ -128,7 +133,7 @@
|
|||||||
audioStore.bookTitle = bookTitle;
|
audioStore.bookTitle = bookTitle;
|
||||||
audioStore.voice = voice;
|
audioStore.voice = voice;
|
||||||
audioStore.speed = speed;
|
audioStore.speed = speed;
|
||||||
audioStore.nextChapter = nextChapter ?? null;
|
// nextChapter is kept in sync by the $effect above — no need to write it here
|
||||||
audioStore.status = 'loading';
|
audioStore.status = 'loading';
|
||||||
audioStore.errorMsg = '';
|
audioStore.errorMsg = '';
|
||||||
|
|
||||||
|
|||||||
@@ -179,9 +179,11 @@
|
|||||||
audioStore.isPlaying = false;
|
audioStore.isPlaying = false;
|
||||||
saveAudioTime();
|
saveAudioTime();
|
||||||
if (audioStore.autoNext && audioStore.nextChapter !== null && audioStore.slug) {
|
if (audioStore.autoNext && audioStore.nextChapter !== null && audioStore.slug) {
|
||||||
audioStore.autoStartPending = true;
|
audioStore.autoStartPending = true;
|
||||||
goto(`/books/${audioStore.slug}/chapters/${audioStore.nextChapter}`);
|
goto(`/books/${audioStore.slug}/chapters/${audioStore.nextChapter}`).catch(() => {
|
||||||
}
|
audioStore.autoStartPending = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
preload="metadata"
|
preload="metadata"
|
||||||
style="display:none"
|
style="display:none"
|
||||||
|
|||||||
Reference in New Issue
Block a user