HTML5 Multi-Channel Sound
December 5, 2010 in Firefox, Games, My Games, My Software, Software by Raptor85
I thought I’d share this.
I’ve been doing some stuff with html5 and hit the issue of one audio object only being able to play one instance of the sound, and that even copying it doesn’t work. (and re-loading it causes another full download on some implementations)
It took a few tries but I’m happy as to how this one turned out, it lets you play sounds via their Id tag and automatically rotates “channels” per sound. (the maximum number of channels you can set in a global variable outside the “class”).
It’s pretty much just a helper class, you can toss this in the source and it pulls any audio tags that were added to the page and sets them up for you, I added in checking for the string “bgm” anywhere in the id as a cheap way to tell it to NOT pre-load “background music” files. (since they only need play one at a time). It works well enough for my causes, hopefully someone else can find it of use.
With this added to the page, simply call “playeffect” or “playmusic” with the id of the audio object to play and it will take care of the rest for you.
Read the rest of this entry →
