Skip to content

Commit

Permalink
Start music on web on 2nd click (Join -> Dark Mode)
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Dec 18, 2023
1 parent 9810f06 commit ad471b7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@
});
observer.observe(bevy, { attributes: true });


// Play background music
let clicks = 0;
function playMusic() {
// Trigger and remove the event listener on the second click
clicks++;
if (clicks < 2) {
return;
} else {
document.removeEventListener('click', playMusic);
}

// Create an AudioContext
const audioContext = new (window.AudioContext || window.webkitAudioContext)();

Expand Down Expand Up @@ -75,9 +85,6 @@
};

request.send();

// Remove the click event listener after the first click
document.removeEventListener('click', playMusic);
}

// Add an event listener for the DOMContentLoaded event (if the browser supports the Web Audio API)
Expand Down

0 comments on commit ad471b7

Please sign in to comment.