client: fix play when nothin' was playin'

This commit is contained in:
geoffrey45
2021-12-24 13:33:38 +03:00
parent 757d6cbe5a
commit ff0381122e
4 changed files with 68 additions and 13 deletions
+28 -5
View File
@@ -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 };