canPlayType is nearly useless

Go ahead, look at the documentation for this function. For those of you who don’t like to follow links, you would be looking at the documentation for a function attached to any html5 video element. It accepts a mimeType, a set of codecs and well… here is the the rub. What would you expect it to return?

I expected a boolean. The guy who worked on this problem before me tested it as though it were a boolean…

if (video.canPlayType(mime + ";codecs='" + codec + "'"))

In fact, after polling the friends around me, every single one of the 15 people I have asked expected the same. In reality it returns either “probably”, “maybe” or “”. This is probably the most non-committal function in the history of time.

Further, imagine my surprise when I opened Safari up, yes I’m on a mac, and passed it 20 different combinations of videos and codecs, all of them return something odd – “maybe”. Not only did this happen for mpeg, which is absolutely supported, but it also returned maybe for wmv and avi files, which were absolutely not supported. I can only hope that this function works better on the iPad/iPhone and Android devices.

Until then, I’m going to be using something else.

2 thoughts on “canPlayType is nearly useless”

  1. I am curious as to why you would ever want this? Supplying mutliple source elements as children of either a video element or audio element is the best way (With a flash fallback of course 😉 )

  2. A good question indeed!

    The usage in the code at this point is to test a series of video entries coming in the form of a vast response from a third party vendor. The reason we cannot rely on the fall back, as i was told – i am not sure its true – is because we need to ready up a number of events (6 in total) to ensure that they are executed appropriately and notifying advertisers when their ads play, Relying on the fall back was causing issues with timing and tracking information previously, so we took to ensuring that the video was a format that could be played before weighing the videos based on bit-rate and then executing the events on the winner.

    Otherwise i would imagine the fall backs would work fine.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.