12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- /*!
- {
- "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() {
- 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;
- });
- });
|