From 847dabb9a4e9958c17bb6a62c950ff50050ebc3c Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Sun, 19 Dec 2021 14:40:27 +0300 Subject: [PATCH] fix audio playing --- server/app/api.py | 2 -- src/composables/getFiles.js | 6 +++--- src/composables/playAudio.js | 9 +++++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/server/app/api.py b/server/app/api.py index 04a8004f..03d7fdbe 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -244,11 +244,9 @@ def getArtistData(): def getFolderTree(folder: str = None): if folder == "$home": requested_dir = home_dir - else: try: req_dir, last_id = folder.split('::') - print(req_dir) except (ValueError): req_dir = folder last_id = None diff --git a/src/composables/getFiles.js b/src/composables/getFiles.js index ac6411b2..782a4ace 100644 --- a/src/composables/getFiles.js +++ b/src/composables/getFiles.js @@ -7,12 +7,12 @@ const getData = async (path, last_id) => { const songs = ref(null); const folders = ref(null); - path = encodeURIComponent(path.replaceAll("/", "|")); + const encoded_path = encodeURIComponent(path.replaceAll("/", "|")); if (last_id) { - url = `${folders_uri}/f/${path}::${last_id}`; + url = `${folders_uri}/f/${encoded_path}::${last_id}`; } else { - url = url = `${folders_uri}/f/${path}`; + url = url = `${folders_uri}/f/${encoded_path}`; } const res = await fetch(url); diff --git a/src/composables/playAudio.js b/src/composables/playAudio.js index fb9c30bc..663d8855 100644 --- a/src/composables/playAudio.js +++ b/src/composables/playAudio.js @@ -1,6 +1,11 @@ -const playAudio = (path) => { - const audio = new Audio("http://127.0.0.1:8901" + path); +import { ref } from "@vue/reactivity"; +const audio = ref(new Audio()).value; + +const playAudio = (path) => { + const full_path = "http://127.0.0.1:8901/" + encodeURIComponent(path); + + audio.src = full_path; audio.addEventListener("canplaythrough", () => { audio.play(); });