Skip to content

Instantly share code, notes, and snippets.

@sirbrad
Created December 7, 2011 11:46
Show Gist options
  • Save sirbrad/1442523 to your computer and use it in GitHub Desktop.
Save sirbrad/1442523 to your computer and use it in GitHub Desktop.
Code for when working with HTML5 Video
// Below code relies on Modernizr to do element support checks.
// Check format browser supports
(function format(){
return {
ogg: !!Modernizr.video.ogg,
webm: !!Modernizr.video.webm,
mp4: !!Modernizr.video.h264
}
}());
// Check for HTML5 video support and set type attributes
if (!!Modernizr.video) {
if (format.ogg) {
ext = '.ogv';
player.setAttribute('type', "video/ogg; codecs='theora, vorbis'")
} else if (format.mp4) {
ext = '.mp4';
player.setAttribute('type', "video/mp4; codecs='avc1.42E01E, mp4a.40.2'");
} else if (format.webm) {
ext = '.webm';
player.setAttribute('type', "video/; codecs='vp8, vorbis'");
}
} else {
ext = '.swf';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment