Move source to currentSong.source

This commit is contained in:
Neshura 2024-04-22 20:07:41 +02:00
parent 2bad02d27e
commit 20499ca5a1
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -56,6 +56,7 @@
title, title,
artist artist
}, },
source,
queueIndex queueIndex
}); });
let isPaused = $state(true); let isPaused = $state(true);
@ -135,12 +136,12 @@
//{ parameter: "converted", value: } // TODO? Only Video related //{ parameter: "converted", value: } // TODO? Only Video related
]; ];
let url = OpenSubsonic.getApiUrl("stream", parameters); let url = OpenSubsonic.getApiUrl("stream", parameters);
source = new Audio(url); // Assign new URL currentSong.source = new Audio(url); // Assign new URL
currentSong.data = song; currentSong.data = song;
// Reassign Event Handlers // Reassign Event Handlers
source.onloadedmetadata = () => { currentSong.source.onloadedmetadata = () => {
duration = source.duration; duration = currentSong.source.duration;
}; };
source.onplay = () => { source.onplay = () => {
@ -148,12 +149,12 @@
isPaused = source.paused; isPaused = source.paused;
} }
source.onpause = () => { currentSong.source.onpause = () => {
isPaused = source.paused; isPaused = currentSong.source.paused;
} }
source.ontimeupdate = () => { currentSong.source.ontimeupdate = () => {
progress = source.currentTime; progress = currentSong.source.currentTime;
} }
currentSong.source.onended = () => { currentSong.source.onended = () => {
@ -161,13 +162,15 @@
currentSong.source.play(); currentSong.source.play();
} }
} }
currentSong.source.load();
} }
function play() { function play() {
source.play().catch(() => {}); currentSong.source.play().catch(() => {});
} }
function pause() { function pause() {
source.pause(); currentSong.source.pause();
} }
function changeVolume(change: number) { function changeVolume(change: number) {
@ -184,6 +187,7 @@
if (currentSong.source) { if (currentSong.source) {
currentSong.source.volume = volume; currentSong.source.volume = volume;
} }
}
function progressPercent() { function progressPercent() {
return progress / duration * 100 || 0; return progress / duration * 100 || 0;
@ -207,7 +211,7 @@
fetchQueue().then(() => { fetchQueue().then(() => {
fetchNowPlaying(); fetchNowPlaying();
}); });
source = new Audio(); currentSong.source = new Audio();
}) })
</script> </script>