Skip to content

Commit

Permalink
try/catch'ing our audio/video tests, as IE9 likes to throw exceptions…
Browse files Browse the repository at this point in the history
… in some rare cases. details:

it seems that if you don't have the "Desktop Experience" installed, using elem.canPlayType()
will throw an exception. Awesome!

So we try/catch it. It's okay, they're cheap.

I'm doing a little bit of magic with an assignment inside my if() conditional. I hope nobody minds, too much.

Fixes Modernizr#224
  • Loading branch information
paulirish committed May 20, 2011
1 parent af7de68 commit b51f17b
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions modernizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,37 +656,45 @@ window.Modernizr = (function( window, document, undefined ) {

tests['video'] = function() {
var elem = document.createElement('video'),
bool = !!elem.canPlayType;

if ( bool ) {
bool = new Boolean(bool);
bool.ogg = elem.canPlayType('video/ogg; codecs="theora"');
bool = false;

// IE9 Running on Windows Server SKU can cause an exception to be thrown, bug #224
try {
if ( bool = !!elem.canPlayType ) {
bool = new Boolean(bool);
bool.ogg = elem.canPlayType('video/ogg; codecs="theora"');

// Workaround required for IE9, which doesn't report video support without audio codec specified.
// bug 599718 @ msft connect
var h264 = 'video/mp4; codecs="avc1.42E01E';
bool.h264 = elem.canPlayType(h264 + '"') || elem.canPlayType(h264 + ', mp4a.40.2"');
// Workaround required for IE9, which doesn't report video support without audio codec specified.
// bug 599718 @ msft connect
var h264 = 'video/mp4; codecs="avc1.42E01E';
bool.h264 = elem.canPlayType(h264 + '"') || elem.canPlayType(h264 + ', mp4a.40.2"');

bool.webm = elem.canPlayType('video/webm; codecs="vp8, vorbis"');
}
bool.webm = elem.canPlayType('video/webm; codecs="vp8, vorbis"');
}

} catch(e) { }

return bool;
};

tests['audio'] = function() {
var elem = document.createElement('audio'),
bool = !!elem.canPlayType;

if ( bool ) {
bool = new Boolean(bool);
bool.ogg = elem.canPlayType('audio/ogg; codecs="vorbis"');
bool.mp3 = elem.canPlayType('audio/mpeg;');

// Mimetypes accepted:
// https://developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
// http://bit.ly/iphoneoscodecs
bool.wav = elem.canPlayType('audio/wav; codecs="1"');
bool.m4a = elem.canPlayType('audio/x-m4a;') || elem.canPlayType('audio/aac;');
}
bool = false;

try {
if ( bool = !!elem.canPlayType ) {
bool = new Boolean(bool);
bool.ogg = elem.canPlayType('audio/ogg; codecs="vorbis"');
bool.mp3 = elem.canPlayType('audio/mpeg;');

// Mimetypes accepted:
// https://developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
// http://bit.ly/iphoneoscodecs
bool.wav = elem.canPlayType('audio/wav; codecs="1"');
bool.m4a = elem.canPlayType('audio/x-m4a;') || elem.canPlayType('audio/aac;');
}
} catch(e) { }

return bool;
};

Expand Down

0 comments on commit b51f17b

Please sign in to comment.