A music player that connects to your cloud/distributed storage.
1import foundation from "~/common/foundation.js";
2import { effect } from "~/common/signal.js";
3
4// Set doc title
5document.title = "Now Playing | Diffuse";
6
7const output = await foundation.orchestrator.output();
8const queue = await foundation.engine.queue();
9
10effect(() => {
11 const now = queue.now();
12 const tracksCol = output.tracks.collection();
13 const isLoadingTracks = tracksCol.state !== "loaded";
14 const currentlyPlaying = now && tracksCol.state === "loaded"
15 ? tracksCol.data.find((t) => t.id === now.id)
16 : undefined;
17 const tags = currentlyPlaying?.tags;
18
19 const element =
20 /** @type {HTMLElement | null} */ (document.querySelector("#now-playing"));
21 if (!element) return;
22
23 if (currentlyPlaying) {
24 element.innerText = `${tags?.artist ?? "Unknown artist"} - ${
25 tags?.title ?? "Unknown title"
26 }`;
27 } else if (isLoadingTracks) {
28 // Keep original text
29 } else {
30 element.innerText = "Nothing is playing yet";
31 }
32});
33
34/** @type {HTMLButtonElement} */ (document.body.querySelector("button"))
35 .onclick = () => {
36 queue.shift();
37 };