From ff0381122e46417e451024bde6fcc9c225ef86f2 Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Fri, 24 Dec 2021 13:33:38 +0300 Subject: [PATCH] client: fix play when nothin' was playin' --- src/assets/icons/play.svg | 5 +-- src/components/RightSideBar/NowPlaying.vue | 38 +++++++++++++++++++--- src/components/RightSideBar/UpNext.vue | 5 +-- src/composables/playAudio.js | 33 ++++++++++++++++--- 4 files changed, 68 insertions(+), 13 deletions(-) diff --git a/src/assets/icons/play.svg b/src/assets/icons/play.svg index 1cf13cf..d426214 100644 --- a/src/assets/icons/play.svg +++ b/src/assets/icons/play.svg @@ -1,3 +1,4 @@ - - + + + diff --git a/src/components/RightSideBar/NowPlaying.vue b/src/components/RightSideBar/NowPlaying.vue index 5a18dfe..f6566b1 100644 --- a/src/components/RightSideBar/NowPlaying.vue +++ b/src/components/RightSideBar/NowPlaying.vue @@ -18,7 +18,15 @@
- +
@@ -27,7 +35,11 @@
@@ -52,8 +64,22 @@ export default { const { playNext } = playAudio; const { playPrev } = playAudio; const { playPause } = playAudio; + const isPlaying = playAudio.playing; - return { current, putCommas, playNext, playPrev, playPause, pos }; + const seek = () => { + playAudio.seek(document.getElementById("progress").value); + }; + + return { + current, + putCommas, + playNext, + playPrev, + playPause, + pos, + seek, + isPlaying, + }; }, }; @@ -142,7 +168,11 @@ export default { background-image: url(../../assets/icons/previous.svg); } - #play-pause { + .play-pause { + background-image: url(../../assets/icons/play.svg); + } + + .isPlaying { background-image: url(../../assets/icons/pause.svg); } diff --git a/src/components/RightSideBar/UpNext.vue b/src/components/RightSideBar/UpNext.vue index 74460d6..96163a5 100644 --- a/src/components/RightSideBar/UpNext.vue +++ b/src/components/RightSideBar/UpNext.vue @@ -31,9 +31,9 @@ }" >
-

{{ song.title }}

+

{{ song.title }}


-

+

{{ artist }} @@ -191,6 +191,7 @@ export default { } .up-next .all-items .song-item .artist { + width: 20rem; font-size: small; color: rgba(255, 255, 255, 0.637); } diff --git a/src/composables/playAudio.js b/src/composables/playAudio.js index 587fb66..f9b4815 100644 --- a/src/composables/playAudio.js +++ b/src/composables/playAudio.js @@ -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 };