Skip to content

Commit 2a98584

Browse files
committed
fixed audio not playing if still playing
1 parent 471fbe5 commit 2a98584

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

assets/scripts/script.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ function showResponse(response) {
1010

1111
function checkInstall(response) {
1212
if (response.installationStatus == false) {
13-
alert("WEBweb/fishing Installation not found.\nPlease make sure you have WEBweb/fishing installed on Steam!");
1413
window.pywebview.api.closeApplication();
1514
} else {
1615
setTimeout(() => openWindow(), 1000);
@@ -46,13 +45,16 @@ function preloadAudio(files) {
4645
}
4746

4847
function playAudio(url) {
49-
const audio = preloadedAudio[url];
48+
const audio = preloadedAudio[url]; // Get the preloaded audio object
5049
if (audio) {
51-
audio.play().catch(error => {
50+
const audioClone = audio.cloneNode(); // Clone the preloaded audio element
51+
audioClone.play().catch(error => {
5252
console.error("Error playing audio:", error);
5353
});
54-
audio.addEventListener("ended", () => {
55-
audio.remove();
54+
55+
// Optional: Clean up the audio element after it finishes playing
56+
audioClone.addEventListener("ended", () => {
57+
audioClone.remove(); // Clean up the cloned audio element
5658
});
5759
} else {
5860
console.warn(`Audio file ${url} is not preloaded.`);

0 commit comments

Comments
 (0)