Friday, February 18, 2011

HTML5 Audio is Still Too Immature to Use in Games

I made a little HTML game a year and a half ago that made some basic use of HTML5 audio, and it worked well enough, but it was very finicky, but I could see HTML5 audio eventually being useful once it matured.

Recently, I reprogrammed an old XNA game I wrote into HTML5 (I never want to go near XNA coding or the XNA community ever again), and I was hoping to program a much more extensive audio engine for the game. Unfortunately, I found HTML5 audio support to be just as finicky as before. Apparently the iPhone/iPad can't play more than one audio stream at once, meaning you can't play music and sound effects at the same time, so it's not possible to make HTML5 games that work well on the iPhone and iPad (basically, all of Apple's talk about HTML5 being superior to Flash on the iPhone and iPad was just propaganda and not reality). Firefox doesn't play short audio files, so the bips, clicks, and other sounds for button presses won't play. Chrome (and possibly Safari too) will not let you play an audio file more than once unless you serve the file from certain types of web servers. The audio in Chrome just sort of dies out after a while anyway, so you don't get any sound after a while. The Internet Explorer 9 Release Candidate seems to only support mp3 files for audio, and using mp3 files in games requires the payment of a licensing fee of $2500 to the mp3 licensing guys. So basically, it's not possible to build a very basic, reliable sound engine for HTML5 games right now.

This struck me as strange though because there are plenty of HTML5 demos and games that have extensive sound support. How can they pull off reliable sound while I can't?

They cheat, of course. All of these games make use of one of these common JavaScript sound libraries like SoundManager2. The dirty little secret is that these libraries will always use Flash for their sound unless Flash support isn't available. Flash is able to offer reliable, solid sound support across many platforms, so developers are able to build solid sound engines for their HTML5 games on top of it. If you try using pure HTML5 audio, things just fall apart.

Perhaps by this time next year, it will be possible to build a pure HTML5 game with good sound and graphics. I haven't used Firefox 4 yet, but I have high hopes for it. Until then, I think Flash is still the only viable platform for online games.


  1. I'm running into the same issues w/ my HTML5 game. All the graphic stuff works great but audio seriously blows and it blows differently from browser to browser.

  2. And what about 'Impact' library?
    They claim to use pure html5: indeed I tried the game 'Biolab disaster' (with flash and silverlight plugins disabled) and sound worked very well (music and effects at the same time).

  3. If you're targeting html5, you're targeting the leading edge of browser support. As a result, things are constantly evolving and you have to be prepared for things to change from day to day. In fact, this post was mainly motivated by my disappointment that sound support hadn't evolved much in the preceding 1.5 years since I had last played with html5 audio.

    Chrome audio support firmed up over the summer. Ie9 always had decent audio support as long as you were willing to pay $2500 to for the rights to include mp3s in your game. I don't know about Firefox, and I don't think there has been much change in the mobile space.

    Of course, the fact that sound support is fine now only means that html5 audio is ok for little experimental stuff. If you're doing professional programming where you want as many people as possible to have access to your stuff, you'll probably have to wait another year or two more before there's wide enough deployment for it to be worthwhile.