This is a bit of a hack, but I do this:
<audio src="blah.wav" type="audio/wav" preload="preload" id="blah0"></audio> <audio src="blah.wav" type="audio/wav" preload="preload" id="blah1"></audio> <audio src="blah.wav" type="audio/wav" preload="preload" id="blah2"></audio> <audio src="blah.wav" type="audio/wav" preload="preload" id="blah3"></audio> var audioStore = [ document.getElementById('blah0'), document.getElementById('blah1'), document.getElementById('blah2'), document.getElementById('blah3'), ]; var n = 0; function playBlah () {
Do it as much as you need. Bonus: you donβt lose the tail of your sound, so you can afford to use the atmosphere (games sometimes want sounds to overlap, for example).
There are more elegant ways to do this. I would actually write a function that takes the name of the audio file, the id line (for example, blah in the example) and several elements for cyclic transition (maximum simultaneous value for this sound) and returns a function that can be called to play the sound. This function will also add elements to the page.
Finally, you probably should use at least MP3 and Wav to get the biggest x-browser compatibility spread, the more formats are better, since the wave is a lot of bandwidth.
Hope this helps. (I used this technique in Chrome, Firefox, Ice Weasel) on Win, Mac OSX and Linux.
SamMorrowDrums
source share