Skip to content

Commit

Permalink
fixed audio not playing if still playing
Browse files Browse the repository at this point in the history
  • Loading branch information
nyxical420 committed Nov 9, 2024
1 parent 471fbe5 commit 2a98584
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions assets/scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function showResponse(response) {

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

function playAudio(url) {
const audio = preloadedAudio[url];
const audio = preloadedAudio[url]; // Get the preloaded audio object
if (audio) {
audio.play().catch(error => {
const audioClone = audio.cloneNode(); // Clone the preloaded audio element
audioClone.play().catch(error => {
console.error("Error playing audio:", error);
});
audio.addEventListener("ended", () => {
audio.remove();

// Optional: Clean up the audio element after it finishes playing
audioClone.addEventListener("ended", () => {
audioClone.remove(); // Clean up the cloned audio element
});
} else {
console.warn(`Audio file ${url} is not preloaded.`);
Expand Down

0 comments on commit 2a98584

Please sign in to comment.