diff --git a/musicroom.db b/musicroom.db index 51bad83..4fd9579 100644 Binary files a/musicroom.db and b/musicroom.db differ diff --git a/public/app.js b/public/app.js index 633ee1f..4232185 100644 --- a/public/app.js +++ b/public/app.js @@ -16,6 +16,7 @@ let currentIndex = 0; let currentUser = null; let serverStatus = null; + let library = []; let prefetchController = null; let loadingSegments = new Set(); let trackCaches = new Map(); // Map of filename -> Set of cached segment indices @@ -453,6 +454,10 @@ function renderPlaylist() { const container = $("#playlist"); container.innerHTML = ""; + if (playlist.length === 0) { + container.innerHTML = '
Playlist empty
'; + return; + } playlist.forEach((track, i) => { const div = document.createElement("div"); div.className = "track" + (i === currentIndex ? " active" : ""); @@ -486,6 +491,46 @@ }); } + function renderLibrary() { + const container = $("#library"); + container.innerHTML = ""; + if (library.length === 0) { + container.innerHTML = '
No tracks discovered
'; + return; + } + library.forEach((track) => { + const div = document.createElement("div"); + div.className = "track"; + const title = track.title?.trim() || track.filename.replace(/\.[^.]+$/, ""); + div.innerHTML = `${title}${fmt(track.duration)}`; + div.onclick = async () => { + // In local mode, play directly from library + if (!synced) { + currentFilename = track.filename; + serverTrackDuration = track.duration; + $("#track-title").textContent = title; + loadingSegments.clear(); + const cachedUrl = await loadTrackBlob(track.filename); + audio.src = cachedUrl || getTrackUrl(track.filename); + audio.currentTime = 0; + localTimestamp = 0; + audio.play(); + } + }; + container.appendChild(div); + }); + } + + async function loadLibrary() { + try { + const res = await fetch("/api/library"); + library = await res.json(); + renderLibrary(); + } catch (e) { + console.warn("Failed to load library"); + } + } + async function handleUpdate(data) { if (!data.track) { $("#track-title").textContent = "No tracks"; @@ -820,6 +865,7 @@ // Initialize Promise.all([initStorage(), loadServerStatus()]).then(() => { + loadLibrary(); loadCurrentUser().then(() => { if (currentUser) loadStreams(); }); diff --git a/public/index.html b/public/index.html index d8cb8ea..8651708 100644 --- a/public/index.html +++ b/public/index.html @@ -35,36 +35,53 @@
-
-