mirror of
https://github.com/Modernizr/Modernizr.git
synced 2026-01-09 15:47:55 -05:00
51 lines
1.8 KiB
JavaScript
51 lines
1.8 KiB
JavaScript
/*!
|
|
{
|
|
"name" : "HTML5 Audio Element",
|
|
"property": "audio",
|
|
"tags" : ["html5", "audio", "media"]
|
|
}
|
|
!*/
|
|
/* DOC
|
|
Detects the audio element
|
|
*/
|
|
define(['Modernizr', 'createElement'], function(Modernizr, createElement) {
|
|
// 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.audio.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() {
|
|
/* jshint -W053 */
|
|
var elem = createElement('audio');
|
|
var bool = false;
|
|
|
|
try {
|
|
bool = !!elem.canPlayType
|
|
if (bool) {
|
|
bool = new Boolean(bool);
|
|
bool.ogg = elem.canPlayType('audio/ogg; codecs="vorbis"') .replace(/^no$/, '');
|
|
bool.mp3 = elem.canPlayType('audio/mpeg; codecs="mp3"') .replace(/^no$/, '');
|
|
bool.opus = elem.canPlayType('audio/ogg; codecs="opus"') ||
|
|
elem.canPlayType('audio/webm; codecs="opus"') .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;
|
|
});
|
|
});
|