HTML5 audio and video tags and Mozilla Firefox

One of the best things about HTML5 is that audio and video can be directly embedded in web pages in the obvious way — i.e. like images — with no weird third-party plugins or JavaScript required. This is a good thing. Unfortunately, while we’ve come to expect IE to not support anything good, it’s pretty disappointing to see that Mozilla has opted to only support the useless Ogg/Theora open source codecs. This means that in addition to having to code workarounds for IE (check for support for the tags, OK no problem) we have to check for support for specific codecs — and these checks are pretty damn annoying.

Checking for <video> or <audio> tag support is pretty straightforward:

function supportsVideoTag(){
    return !!document.createElement('video').canPlayType;

(I’ll leave figuring out how to do the same thing for audio tags as an exercise to the reader.)

But to check for specific format/codec support you need to actually verify that the specific file you’re wanting to play back is supported, which not only makes the code more complicated, but requires you to figure out the MIME string representing your file type, e.g. ‘audio/mp3’ or — worse — ‘video/x-new-fictional-format;codecs=”kittens,bunnies”‘ as the whatwg’s example puts it.

Here’s the thing — it would be nice to know that there’s some format — mp3 for audio, say — that will work 99% of the time if audio tag support is there. As it is, Firefox won’t play MP3s at all, and Webkit considers mp3s to be “audio/mpeg” while Chrome considers them to be “audio/mp3”. Heckuva job.

All this kind of defeats the whole point of “you can just embed audio/video in your web page without needing JavaScript and it will all Just Work”, right? So what possible reason can the Mozilla folk have for exacerbating this stupidity?

The general argument made by advocates off Ogg/Theora is that it’s Open Source and not subject to patent issues the way MP3 or H264, say, are. But the only reason that Ogg/Theora hasn’t been sued yet is that no-one uses it or cares about it. The GIF lawsuit only occurred when there was a paycheck involved. No-one is going to wake up their legal dream team to sue someone over zero revenue. In any event, calling APIs provided by OS vendors doesn’t expose you to anything. All the graphic rendering in OS X is done via proprietary fonts, using OpenGL and Apple’s implementation of Display Postscript. If you want to stick a pixel on the screen you’re calling OS subroutines that invoke code that infringes on all kinds of possible IP law. It’s. Not. Your. Problem.

Another argument is that Mozilla is trying to Do Good by forcing people away from Evil Proprietary Formats like MP3, AAC, H264, and Flash. But in fact what they’re doing is forcing us to pick an Evil Proprietary Format and Evil Proprietary HTML that will work as well as possible in as many places as possible, and that sure as hell isn’t going to be Ogg/Theora.

If Mozilla would pull its head out of its ass and support H264 then we could use video tags to deal with every platform except (1) Richard Stallman’s crippled netbook and (2) IE. We can support IE by wrapping the H264 in simple HTML which passes it to WMP or hot-swapping an Open Source Flash player into the tags (Flash will still not be open source, but the player can be).

And, in my case, Mozilla is forcing me to stop using Firefox. (Guess what? Webkit’s debugging tools are now ahead of Firefox’s anyway.)

Anyway, I’m now happily using Webkit on my Macs and Chrome under Windows (Chrome is still a bit too crippled on the Mac for me to love it).