Skip to content

Commit

Permalink
Move audio test to feature-detects/audio.js
Browse files Browse the repository at this point in the history
  • Loading branch information
seutje committed Sep 21, 2012
1 parent ea76435 commit f968719
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
35 changes: 35 additions & 0 deletions feature-detects/audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

// This tests evaluates support of the audio element, as well as
// testing what types of content it supports.
//
// We're using the Boolean constructor here, so that we can extend the value
// e.g. Modernizr.audio // true
// Modernizr.video.ogg // 'probably'
//
// Codec values from : github.com/NielsLeenheer/html5test/blob/9106a8/index.html#L845
// thx to NielsLeenheer and zcorpan

// Note: in some older browsers, "no" was a return value instead of empty string.
// It was live in FF3.5.0 and 3.5.1, but fixed in 3.5.2
// It was also live in Safari 4.0.0 - 4.0.4, but fixed in 4.0.5
Modernizr.addTest('audio', function() {
var elem = document.createElement('audio'),
bool = false;

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

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

return bool;
});
22 changes: 0 additions & 22 deletions modernizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,28 +624,6 @@ window.Modernizr = (function( window, document, undefined ) {
return bool;
};

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

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

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

return bool;
};


/*>>webforms*/
// input features and input types go directly onto the ret object, bypassing the tests loop.
Expand Down

0 comments on commit f968719

Please sign in to comment.