autoplay-retry
This commit is contained in:
parent
7bb21c245c
commit
c09b5f4308
1 changed files with 7 additions and 2 deletions
|
|
@ -12,6 +12,7 @@
|
|||
let duration = $state(0);
|
||||
let loading = $state(false);
|
||||
let errored = $state(false);
|
||||
let intent = $state(false);
|
||||
|
||||
function toggle() {
|
||||
if (errored) {
|
||||
|
|
@ -20,9 +21,11 @@
|
|||
}
|
||||
if (!audio) return;
|
||||
if (audio.paused) {
|
||||
intent = true;
|
||||
if (audio.readyState < 3) loading = true;
|
||||
audio.play().catch(() => undefined);
|
||||
} else {
|
||||
intent = false;
|
||||
audio.pause();
|
||||
}
|
||||
}
|
||||
|
|
@ -30,6 +33,7 @@
|
|||
function retry() {
|
||||
if (!audio) return;
|
||||
errored = false;
|
||||
intent = true;
|
||||
loading = true;
|
||||
audio.load();
|
||||
audio.play().catch(() => undefined);
|
||||
|
|
@ -47,7 +51,8 @@
|
|||
|
||||
$effect(() => {
|
||||
if (!autoplay || !audio) return;
|
||||
audio.play().catch(() => undefined);
|
||||
intent = true;
|
||||
audio.play().catch(() => { intent = false; });
|
||||
});
|
||||
|
||||
function fmt(s: number) {
|
||||
|
|
@ -119,7 +124,7 @@
|
|||
bind:duration
|
||||
onloadstart={() => { errored = false; }}
|
||||
oncanplay={() => { loading = false; }}
|
||||
onwaiting={() => { if (!paused) loading = true; }}
|
||||
onwaiting={() => { if (intent) loading = true; }}
|
||||
onplaying={onPlaying}
|
||||
onerror={() => { loading = false; errored = true; }}
|
||||
onended={() => { paused = true; }}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue