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 {
await el.play();
} catch {
// Autoplay may be blocked; bail out quietly.
return;
}
@@ -278,6 +279,23 @@
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");
});

View File

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