From 5e75649a68ed874468e878f535236edfaf487952 Mon Sep 17 00:00:00 2001 From: An! <76437910+IceeAn@users.noreply.github.com> Date: Sat, 2 Dec 2023 14:26:11 +0800 Subject: [PATCH] resolve loadAudioFile error when query string in URL When the URL contains a query string (e.g., "?lang=zh_cn") or is accessed with index.html, loadAudioFile fails to load the audio files. The issue has been resolved by removing that from the URL before before concatenating "src" link. --- script/audio.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/script/audio.js b/script/audio.js index 4b0ffc170..09f75a76d 100644 --- a/script/audio.js +++ b/script/audio.js @@ -204,7 +204,11 @@ var AudioEngine = { }, loadAudioFile: function (src) { if (src.indexOf('http') === -1) { - src = window.location + src; + var path = window.location.protocol + '//' + window.location.hostname + (window.location.port ?(':' + window.location.port) : '') + window.location.pathname; + if(path.endsWith('index.html')){ + path = path.slice(0, - 10); + } + src = path + src; } if (AudioEngine.AUDIO_BUFFER_CACHE[src]) { return new Promise(function (resolve, reject) {