cablegates/static/js/jquery/jquery.videosupport.js

43 lines
1.4 KiB
JavaScript
Raw Normal View History

2011-04-23 19:33:01 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=js
2010-09-03 13:28:44 +00:00
jQuery.support.video = function() {
jQuery.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
var video = {};
var v = document.createElement('video');
if (v) {
video.support = true;
2011-04-23 19:33:01 +00:00
//get supported types
2010-09-03 13:28:44 +00:00
video.webm = !!(v.canPlayType && v.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/no/, ''));
2011-04-23 19:33:01 +00:00
video.h264 = !!(v.canPlayType && v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, ''));
video.ogg = !!(v.canPlayType && v.canPlayType('video/ogg; codecs="theora, vorbis"').replace(/no/, ''));
2010-09-03 13:28:44 +00:00
//Disable WebM on Safari/Perian, seeking does not work
2011-04-23 19:33:01 +00:00
if(!jQuery.browser.chrome &&
video.webm &&
/safari/.test(navigator.userAgent.toLowerCase()) &&
!/linux/.test(navigator.userAgent.toLowerCase())) {
2010-09-03 13:28:44 +00:00
video.webm = false;
2011-03-04 16:10:14 +00:00
}
2011-04-23 19:33:01 +00:00
//use webm if possible
if(jQuery.browser.chrome && video.webm) {
2011-04-07 10:43:22 +00:00
video.h264 = false;
2011-04-23 19:33:01 +00:00
}
//aliases
2011-04-07 09:54:31 +00:00
video.mp4 = video.h264;
2011-02-06 12:40:28 +00:00
video.ogv = video.ogg;
2010-09-03 13:28:44 +00:00
} else {
video.support = false;
}
2011-02-11 10:20:41 +00:00
video.supportedFormat = function(formats) {
var format;
formats.forEach(function(f) {
if(!format && video[f]) {
2011-03-04 16:10:14 +00:00
format = f;
2011-02-11 10:20:41 +00:00
}
});
return format;
2011-03-04 16:10:14 +00:00
};
2010-09-03 13:28:44 +00:00
return video;
}();