Detect if browser can play html5 media format with JavaScript

I love the concept of Modernizr, but when you can do something simple with a couple of lines of JavaScript without loading another library, you probably should.

Say, for example that I want to display a video with HTML5’s <video> tag, but I need to detect wether my browser supports MP4 or Theora.Ogg. You can do it easily with the canPlayType() method. You can simple create a new media element and then use the canPlayType to check for the proper format support.

Continue reading “Detect if browser can play html5 media format with JavaScript”