global player pt. 9 fix play track pt. 2
This commit is contained in:
@@ -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");
|
||||
});
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user