global player pt. 9 fix play track pt. 2

This commit is contained in:
2026-02-06 02:15:11 -08:00
parent 0b1a7792b4
commit 28aed104f6
2 changed files with 25 additions and 0 deletions

View File

@@ -171,6 +171,7 @@
try { try {
await el.play(); await el.play();
} catch { } catch {
// Autoplay may be blocked; bail out quietly.
return; return;
} }
@@ -278,6 +279,23 @@
snap = s; snap = s;
}); });
// Listen for play requests dispatched from anywhere (e.g. SongEntry buttons).
// This ensures "Play" behaves like Next/Prev: it will reliably sync the new
// source and start playback.
if (browser) {
const onAutoplayRequest = () => {
void syncAndAutoplay();
};
window.addEventListener("amqtrain:player:autoplay", onAutoplayRequest);
return () => {
window.removeEventListener(
"amqtrain:player:autoplay",
onAutoplayRequest,
);
};
}
media.setPlaybackState("paused"); media.setPlaybackState("paused");
}); });

View File

@@ -54,6 +54,11 @@
); );
const isQueued = $derived(hasTrack(annSongId)); const isQueued = $derived(hasTrack(annSongId));
function requestGlobalAutoplay() {
if (typeof window === "undefined") return;
window.dispatchEvent(new CustomEvent("amqtrain:player:autoplay"));
}
</script> </script>
<div class="rounded border px-3 py-2"> <div class="rounded border px-3 py-2">
@@ -77,6 +82,7 @@
onclick={() => { onclick={() => {
if (!track) return; if (!track) return;
play(track); play(track);
requestGlobalAutoplay();
}} }}
> >
Play Play
@@ -89,6 +95,7 @@
onclick={() => { onclick={() => {
if (!track) return; if (!track) return;
playNext(track); playNext(track);
requestGlobalAutoplay();
}} }}
> >
Play next Play next