This code uses the Web Audio API to play sounds in the browser.
To get started, include the sounds.js file in head of your project.
<script src="sounds.js" type="text/javascript"></script>
Then edit the sounds object to add your sounds...
"dead" : {
url : "sounds/dead.wav"
},
"ping" : {
url : "sounds/ping.mp3",
volume : .5
}
The name of the sound above will be "dead". You can add an optional volume property, which can range from 0 to 1.
To play a sound, call the method with the name of the sound.
playSound("dead");
🎹
You can also change the volume dynamically, like this...
playSound("dead", { volume: .4 });
🎹