mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
client: fix play when nothin' was playin'
This commit is contained in:
@@ -4,19 +4,25 @@ import perks from "./perks";
|
||||
|
||||
const audio = ref(new Audio()).value;
|
||||
const pos = ref(0);
|
||||
const playing = ref(false)
|
||||
|
||||
const url = "http://127.0.0.1:8901/";
|
||||
|
||||
const playAudio = (path) => {
|
||||
const full_path = url + encodeURIComponent(path);
|
||||
|
||||
audio.src = full_path;
|
||||
setTimeout(() => {
|
||||
audio.src = full_path;
|
||||
}, 150);
|
||||
audio.load();
|
||||
|
||||
audio.play();
|
||||
audio.oncanplaythrough = () => {
|
||||
audio.play();
|
||||
};
|
||||
|
||||
audio.ontimeupdate = () => {
|
||||
pos.value = audio.currentTime / audio.duration * 100;
|
||||
}
|
||||
pos.value = (audio.currentTime / audio.duration) * 100;
|
||||
};
|
||||
|
||||
audio.addEventListener("ended", () => {
|
||||
playNext();
|
||||
@@ -33,7 +39,16 @@ function playPrev() {
|
||||
perks.current.value = perks.prev.value;
|
||||
}
|
||||
|
||||
function seek(pos) {
|
||||
console.log(pos);
|
||||
audio.currentTime = (pos / 100) * audio.duration;
|
||||
}
|
||||
|
||||
function playPause() {
|
||||
if (audio.src === "") {
|
||||
playAudio(perks.current.value.filepath);
|
||||
}
|
||||
|
||||
if (audio.paused) {
|
||||
audio.play();
|
||||
} else {
|
||||
@@ -41,4 +56,12 @@ function playPause() {
|
||||
}
|
||||
}
|
||||
|
||||
export default { playAudio, playNext, playPrev, playPause, pos };
|
||||
audio.addEventListener('play', () => {
|
||||
playing.value = true;
|
||||
})
|
||||
|
||||
audio.addEventListener('pause', () => {
|
||||
playing.value = false;
|
||||
})
|
||||
|
||||
export default { playAudio, playNext, playPrev, playPause, seek, pos, playing };
|
||||
|
||||
Reference in New Issue
Block a user