From 20499ca5a1735a0048f065e7381a86267d698312 Mon Sep 17 00:00:00 2001 From: Neshura Date: Mon, 22 Apr 2024 20:07:41 +0200 Subject: [PATCH] Move source to currentSong.source --- src/routes/+page.svelte | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 80ecc13..092481d 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -56,6 +56,7 @@ title, artist }, + source, queueIndex }); let isPaused = $state(true); @@ -135,12 +136,12 @@ //{ parameter: "converted", value: } // TODO? Only Video related ]; let url = OpenSubsonic.getApiUrl("stream", parameters); - source = new Audio(url); // Assign new URL + currentSong.source = new Audio(url); // Assign new URL currentSong.data = song; // Reassign Event Handlers - source.onloadedmetadata = () => { - duration = source.duration; + currentSong.source.onloadedmetadata = () => { + duration = currentSong.source.duration; }; source.onplay = () => { @@ -148,12 +149,12 @@ isPaused = source.paused; } - source.onpause = () => { - isPaused = source.paused; + currentSong.source.onpause = () => { + isPaused = currentSong.source.paused; } - source.ontimeupdate = () => { - progress = source.currentTime; + currentSong.source.ontimeupdate = () => { + progress = currentSong.source.currentTime; } currentSong.source.onended = () => { @@ -161,13 +162,15 @@ currentSong.source.play(); } } + + currentSong.source.load(); } function play() { - source.play().catch(() => {}); + currentSong.source.play().catch(() => {}); } function pause() { - source.pause(); + currentSong.source.pause(); } function changeVolume(change: number) { @@ -184,6 +187,7 @@ if (currentSong.source) { currentSong.source.volume = volume; } + } function progressPercent() { return progress / duration * 100 || 0; @@ -207,7 +211,7 @@ fetchQueue().then(() => { fetchNowPlaying(); }); - source = new Audio(); + currentSong.source = new Audio(); })