Move source to currentSong.source
This commit is contained in:
parent
2bad02d27e
commit
20499ca5a1
1 changed files with 14 additions and 10 deletions
|
@ -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();
|
||||
})
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in a new issue