UNPKG

35.3 kBHTMLView Raw
1<!DOCTYPE html>
2
3<html lang="en">
4<head>
5 <meta charset="utf-8">
6 <meta name="viewport" content="width=device-width">
7 <title>CrossBrowdy API documentation Source: CrossBase/audiovisual/audio/CB_AudioDetector.js</title>
8
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
13
14 <link type="text/css" rel="stylesheet" href="styles/site.cosmo.css">
15
16</head>
17
18<body style="min-width:800px; overflow-wrap:break-word; word-wrap:break-word; word-break:break-word; line-break:strict; hyphens:none; -webkit-hyphens:none; -moz-hyphens:none;">
19
20<div class="navbar navbar-default navbar-fixed-top ">
21<div class="container">
22 <div class="navbar-header">
23 <a class="navbar-brand" href="index.html">CrossBrowdy API documentation</a>
24 <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
25 <span class="icon-bar"></span>
26 <span class="icon-bar"></span>
27 <span class="icon-bar"></span>
28 </button>
29 </div>
30 <div class="navbar-collapse collapse" id="topNavigation">
31 <ul class="nav navbar-nav">
32
33 <li class="dropdown">
34 <a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b class="caret"></b></a>
35 <ul class="dropdown-menu inline">
36 <li><a href="CB_Arrays.html">CB_Arrays</a></li><li><a href="CB_AudioDetector.html">CB_AudioDetector</a></li><li><a href="CB_baseSymbols.html">CB_baseSymbols</a></li><li><a href="CB_Client.html">CB_Client</a></li><li><a href="CB_Collisions.html">CB_Collisions</a></li><li><a href="CB_Configuration.html">CB_Configuration</a></li><li><a href="CB_Configuration.CrossBase.html">CB_Configuration.CrossBase</a></li><li><a href="CB_Configuration.CrossBrowdy.html">CB_Configuration.CrossBrowdy</a></li><li><a href="CB_Controllers.html">CB_Controllers</a></li><li><a href="CB_Controllers_Proprietary.html">CB_Controllers_Proprietary</a></li><li><a href="CB_Controllers_Proprietary.WII.html">CB_Controllers_Proprietary.WII</a></li><li><a href="CB_Controllers_Proprietary.WII_U.html">CB_Controllers_Proprietary.WII_U</a></li><li><a href="CB_Device.html">CB_Device</a></li><li><a href="CB_Device.AmbientLight.html">CB_Device.AmbientLight</a></li><li><a href="CB_Device.Battery.html">CB_Device.Battery</a></li><li><a href="CB_Device.Location.html">CB_Device.Location</a></li><li><a href="CB_Device.Motion.html">CB_Device.Motion</a></li><li><a href="CB_Device.Orientation.html">CB_Device.Orientation</a></li><li><a href="CB_Device.Proximity.html">CB_Device.Proximity</a></li><li><a href="CB_Device.Vibration.html">CB_Device.Vibration</a></li><li><a href="CB_Elements.html">CB_Elements</a></li><li><a href="CB_Events.html">CB_Events</a></li><li><a href="CB_Keyboard.html">CB_Keyboard</a></li><li><a href="CB_Keyboard.chars.html">CB_Keyboard.chars</a></li><li><a href="CB_Keyboard.extended.html">CB_Keyboard.extended</a></li><li><a href="CB_Keyboard.keys.html">CB_Keyboard.keys</a></li><li><a href="CB_Modules.html">CB_Modules</a></li><li><a href="CB_Mouse.html">CB_Mouse</a></li><li><a href="CB_Mouse.CursorImage.html">CB_Mouse.CursorImage</a></li><li><a href="CB_Net.html">CB_Net</a></li><li><a href="CB_Net.Fetch.html">CB_Net.Fetch</a></li><li><a href="CB_Net.REST.html">CB_Net.REST</a></li><li><a href="CB_Net.Sockets.html">CB_Net.Sockets</a></li><li><a href="CB_Net.Sockets.SockJS.html">CB_Net.Sockets.SockJS</a></li><li><a href="CB_Net.XHR.html">CB_Net.XHR</a></li><li><a href="CB_Pointer.html">CB_Pointer</a></li><li><a href="CB_Screen.html">CB_Screen</a></li><li><a href="CB_Speaker.html">CB_Speaker</a></li><li><a href="CB_Touch.html">CB_Touch</a></li>
37 </ul>
38 </li>
39
40 <li class="dropdown">
41 <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
42 <ul class="dropdown-menu inline">
43 <li><a href="CB_AudioFile.html">CB_AudioFile</a></li><li><a href="CB_AudioFile_API.AAPI.html">CB_AudioFile_API.AAPI</a></li><li><a href="CB_AudioFile_API.ACMP.html">CB_AudioFile_API.ACMP</a></li><li><a href="CB_AudioFile_API.SM2.html">CB_AudioFile_API.SM2</a></li><li><a href="CB_AudioFile_API.WAAPI.html">CB_AudioFile_API.WAAPI</a></li><li><a href="CB_AudioFileCache.html">CB_AudioFileCache</a></li><li><a href="CB_AudioFileSprites.html">CB_AudioFileSprites</a></li><li><a href="CB_AudioFileSpritesPool.html">CB_AudioFileSpritesPool</a></li><li><a href="CB_Canvas.html">CB_Canvas</a></li><li><a href="CB_GraphicSprites.html">CB_GraphicSprites</a></li><li><a href="CB_GraphicSpritesScene.html">CB_GraphicSpritesScene</a></li>
44 </ul>
45 </li>
46
47 <li class="dropdown">
48 <a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
49 <ul class="dropdown-menu inline">
50 <li><a href="global.html#CB_addCredits">CB_addCredits</a></li><li><a href="global.html#CB_BASE_NAME">CB_BASE_NAME</a></li><li><a href="global.html#CB_baseToBase">CB_baseToBase</a></li><li><a href="global.html#CB_baseToInt">CB_baseToInt</a></li><li><a href="global.html#CB_br2nl">CB_br2nl</a></li><li><a href="global.html#CB_brToNl">CB_brToNl</a></li><li><a href="global.html#CB_combineArraysOrObjects">CB_combineArraysOrObjects</a></li><li><a href="global.html#CB_combineAutomatically">CB_combineAutomatically</a></li><li><a href="global.html#CB_combineJSON">CB_combineJSON</a></li><li><a href="global.html#CB_combineURIParameters">CB_combineURIParameters</a></li><li><a href="global.html#CB_combineURLParameters">CB_combineURLParameters</a></li><li><a href="global.html#CB_console">CB_console</a></li><li><a href="global.html#CB_copyObject">CB_copyObject</a></li><li><a href="global.html#CB_countDecimalDigits">CB_countDecimalDigits</a></li><li><a href="global.html#CB_countDecimalPart">CB_countDecimalPart</a></li><li><a href="global.html#CB_countDecimals">CB_countDecimals</a></li><li><a href="global.html#CB_countIntegerDigits">CB_countIntegerDigits</a></li><li><a href="global.html#CB_countIntegerPart">CB_countIntegerPart</a></li><li><a href="global.html#CB_credits">CB_credits</a></li><li><a href="global.html#CB_CREDITS_DEFAULT">CB_CREDITS_DEFAULT</a></li><li><a href="global.html#CB_forceString">CB_forceString</a></li><li><a href="global.html#CB_forEach">CB_forEach</a></li><li><a href="global.html#CB_getBase64StringObject">CB_getBase64StringObject</a></li><li><a href="global.html#CB_getCookie">CB_getCookie</a></li><li><a href="global.html#CB_getDatum">CB_getDatum</a></li><li><a href="global.html#CB_getJSONPropertyValue">CB_getJSONPropertyValue</a></li><li><a href="global.html#CB_getLZStringObject">CB_getLZStringObject</a></li><li><a href="global.html#CB_getValueIndex">CB_getValueIndex</a></li><li><a href="global.html#CB_getValuePath">CB_getValuePath</a></li><li><a href="global.html#CB_includeJSFile">CB_includeJSFile</a></li><li><a href="global.html#CB_indexOf">CB_indexOf</a></li><li><a href="global.html#CB_init">CB_init</a></li><li><a href="global.html#CB_intToBase">CB_intToBase</a></li><li><a href="global.html#CB_isArray">CB_isArray</a></li><li><a href="global.html#CB_isEmail">CB_isEmail</a></li><li><a href="global.html#CB_isFileLocal">CB_isFileLocal</a></li><li><a href="global.html#CB_isString">CB_isString</a></li><li><a href="global.html#CB_lastIndexOf">CB_lastIndexOf</a></li><li><a href="global.html#CB_ltrim">CB_ltrim</a></li><li><a href="global.html#CB_NAME">CB_NAME</a></li><li><a href="global.html#CB_nl2br">CB_nl2br</a></li><li><a href="global.html#CB_nlToBr">CB_nlToBr</a></li><li><a href="global.html#CB_numberFormat">CB_numberFormat</a></li><li><a href="global.html#CB_numberOfDecimalDigits">CB_numberOfDecimalDigits</a></li><li><a href="global.html#CB_numberOfDecimals">CB_numberOfDecimals</a></li><li><a href="global.html#CB_numberOfIntegerDigits">CB_numberOfIntegerDigits</a></li><li><a href="global.html#CB_OPTIONS">CB_OPTIONS</a></li><li><a href="global.html#CB_parseJSON">CB_parseJSON</a></li><li><a href="global.html#CB_parseString">CB_parseString</a></li><li><a href="global.html#CB_regularExpressionString">CB_regularExpressionString</a></li><li><a href="global.html#CB_renderString">CB_renderString</a></li><li><a href="global.html#CB_replaceAll">CB_replaceAll</a></li><li><a href="global.html#CB_rtrim">CB_rtrim</a></li><li><a href="global.html#CB_scriptPath">CB_scriptPath</a></li><li><a href="global.html#CB_scriptPathCalculate">CB_scriptPathCalculate</a></li><li><a href="global.html#CB_setCookie">CB_setCookie</a></li><li><a href="global.html#CB_setDatum">CB_setDatum</a></li><li><a href="global.html#CB_sizeof">CB_sizeof</a></li><li><a href="global.html#CB_sizeOf">CB_sizeOf</a></li><li><a href="global.html#CB_stringifyJSON">CB_stringifyJSON</a></li><li><a href="global.html#CB_symmetricCall">CB_symmetricCall</a></li><li><a href="global.html#CB_symmetricCallClear">CB_symmetricCallClear</a></li><li><a href="global.html#CB_this">CB_this</a></li><li><a href="global.html#CB_trim">CB_trim</a></li><li><a href="global.html#CB_VERSION">CB_VERSION</a></li>
51 </ul>
52 </li>
53
54 </ul>
55
56 <div class="col-sm-3 col-md-3">
57 <form class="navbar-form" role="search">
58 <div class="input-group">
59 <input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
60 <div class="input-group-btn">
61 <button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
62 </div>
63 </div>
64 </form>
65 </div>
66
67 </div>
68
69</div>
70</div>
71
72
73<div class="container" id="toc-content" style="width:100%;">
74<div class="row" style="width:100%;">
75
76
77 <div class="col-md-12">
78
79 <div id="main">
80
81
82 <h1 class="page-title">Source: CrossBase/audiovisual/audio/CB_AudioDetector.js</h1>
83
84<section>
85 <article>
86 <pre
87 class="sunlight-highlight-javascript linenums">/**
88 * @file Audio formats and audio APIs support detection. Contains the {@link CB_AudioDetector} static class.
89 * @author Joan Alba Maldonado &lt;workindalian@gmail.com>
90 * @license Creative Commons Attribution 4.0 International. See more at {@link https://crossbrowdy.com/about#what_is_the_crossbrowdy_copyright_and_license}.
91 */
92
93
94/**
95 * Static class to detect audio API and formats supported. Possible audio APIs are "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}). It will return itself if it is tried to be instantiated.
96 * @namespace
97 */
98var CB_AudioDetector = function() { return CB_AudioDetector; };
99{
100 CB_AudioDetector.initialized = false; //It will tells whether the object has been initialized or not.
101
102
103 //Initializes all values:
104 CB_AudioDetector.init = function()
105 {
106 if (CB_AudioDetector.initialized) { return CB_AudioDetector; }
107
108 //Sets that the object has already been initialized:
109 CB_AudioDetector.initialized = true;
110
111 //TODO.
112
113 return CB_AudioDetector;
114 }
115
116
117 CB_AudioDetector._getSupportedAudioFormatsReturnCache = {};
118 /**
119 * Returns an array of strings with the audio formats that are supported (from an array if it is given) by the current client and ordered by support level. Uses the {@link CB_AudioDetector.isAudioFormatSupported} function internally.
120 * @function
121 * @param {array} [audioFormats=CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_FORMATS] - An array of strings with the audio format or audio formats (they can include just the format as 'audio/ogg' or also the codec as for example 'audio/ogg; codecs="vorbis"') that we want to check.
122 * @param {array} [supportLevels=['probably', 'maybe']] - An array with the support level or support levels allowed. Two possible levels: "probably" and "maybe". The "probably" audio formats are more likely to be supported than the "maybe" ones.
123 * @param {boolean} [dataURI=false] - Specifies whether we want to check the support for data URI audios or just for normal audio files.
124 * @returns {array} Returns an array of strings with the audio formats that are supported (from an array if it is given) and ordered by support level.
125 */
126 CB_AudioDetector.getSupportedAudioFormats = function(audioFormats, supportLevels, dataURI)
127 {
128 //If not given any APIs, uses the default ones with the default order:
129 if (typeof(audioFormats) === "undefined" || audioFormats === null || !CB_isArray(audioFormats)) { audioFormats = CB_Configuration[CB_BASE_NAME].CB_AudioFileCache_PREFERRED_AUDIO_FORMATS; }
130
131 //If not given, it will return "probably" and "maybe" ones and in that order ("probably" are more likely to be supported than "maybe" ones):
132 if (!CB_isArray(supportLevels)) { supportLevels = ["probably", "maybe"]; }
133
134 //If it is not the first time, returns the same as the first time (from the cache):
135 if (typeof(CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats]) !== "undefined" &amp;&amp; CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats] !== null)
136 {
137 if (typeof(CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats][supportLevels]) !== "undefined" &amp;&amp; CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats][supportLevels] !== null)
138 {
139 if (typeof(CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats][supportLevels][dataURI]) !== "undefined" &amp;&amp; CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats][supportLevels][dataURI] !== null)
140 {
141 return CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats][supportLevels][dataURI];
142 }
143 }
144 }
145
146 var supportedAudioFormats = [];
147
148 var audioFormatsLength = audioFormats.length;
149
150 //Checks the different support levels by order of preference ("probably" are more likely to be supported than "maybe" ones):
151 var supportLevelsLength = supportLevels.length;
152 var y;
153 for (var x = 0; x &lt; supportLevelsLength; x++)
154 {
155 for (y = 0; y &lt; audioFormatsLength; y++)
156 {
157 if (CB_AudioDetector.isAudioFormatSupported(audioFormats[y], dataURI) === supportLevels[x])
158 {
159 if (CB_indexOf(supportedAudioFormats, audioFormats[y]) === -1)
160 {
161 supportedAudioFormats[supportedAudioFormats.length] = audioFormats[y];
162 }
163 }
164 }
165 }
166
167 //Stores the result in the cache for the next time:
168 if (typeof(CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats]) === "undefined")
169 {
170 CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats] = {};
171 }
172 if (typeof(CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats][supportLevels]) === "undefined")
173 {
174 CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats][supportLevels] = {};
175 }
176 CB_AudioDetector._getSupportedAudioFormatsReturnCache[audioFormats][supportLevels][dataURI] = supportedAudioFormats;
177
178 return supportedAudioFormats;
179 }
180
181
182 CB_AudioDetector._isAudioFormatSupportedReturnCache = {};
183 CB_AudioDetector._audioObject = null;
184 /**
185 * Returns the support level of a given audio format by the current client.
186 * @function
187 * @param {string} audioFormat - The audio format (it can include just the format as 'audio/ogg' or also the codec as for example 'audio/ogg; codecs="vorbis"') that we want to check.
188 * @param {boolean} [dataURI=false] - Specifies whether we want to check the support for data URI audios or just for normal audio files.
189 * @returns {string} Returns the support level of the given audio format (it will return "probably", "maybe" or an empty string which means not supported). The "probably" audio formats are more likely to be supported than the "maybe" ones.
190 * @todo Think about using MediaSource.isTypeSupported().
191 * @todo Some web clients does not support data URIs for Audio element so we should take this into account.
192 * @todo Take into account that data URIs may not be supported when WAAPI is being emulated.
193 */
194 CB_AudioDetector.isAudioFormatSupported = function(audioFormat, dataURI)
195 {
196 audioFormat = CB_trim(audioFormat).toLowerCase();
197
198 //If it is not the first time, returns the same as the first time (from the cache):
199 if (typeof(CB_AudioDetector._isAudioFormatSupportedReturnCache[audioFormat]) !== "undefined" &amp;&amp; CB_AudioDetector._isAudioFormatSupportedReturnCache[audioFormat] !== null)
200 {
201 if (typeof(CB_AudioDetector._isAudioFormatSupportedReturnCache[audioFormat][dataURI]) !== "undefined" &amp;&amp; CB_AudioDetector._isAudioFormatSupportedReturnCache[audioFormat][dataURI] !== null)
202 {
203 return CB_AudioDetector._isAudioFormatSupportedReturnCache[audioFormat][dataURI];
204 }
205 }
206
207 var isSupported = "";
208
209 //TODO: think about using MediaSource.isTypeSupported().
210
211 if (CB_AudioDetector.isAPISupported("AAPI", false))
212 {
213 if (CB_AudioDetector._audioObject === null)
214 {
215 CB_AudioDetector._audioObject = new Audio();
216 }
217
218 //TODO: some web clients does not support data URIs for Audio element so we should take this into account.
219
220 if (CB_AudioDetector._audioObject !== null &amp;&amp; typeof(CB_AudioDetector._audioObject.canPlayType) === "function")
221 {
222 isSupported = CB_AudioDetector._audioObject.canPlayType(audioFormat);
223 }
224 }
225 //...otherwise, if SoundManager 2 is loaded and it is using Flash:
226 else if (CB_AudioDetector.isAPISupported("SM2", false) &amp;&amp; CB_AudioDetector.isSM2UsingFlash())
227 {
228 //SoundManager 2 using Flash supports MP3 only and does not support data URIs:
229 if (!dataURI &amp;&amp; audioFormat.substring(0, 10) === "audio/mpeg") { isSupported = "maybe"; }
230 }
231
232 //Stores the result in the cache for the next time:
233 if (typeof(CB_AudioDetector._isAudioFormatSupportedReturnCache[audioFormat]) === "undefined")
234 {
235 CB_AudioDetector._isAudioFormatSupportedReturnCache[audioFormat] = {};
236 }
237 CB_AudioDetector._isAudioFormatSupportedReturnCache[audioFormat][dataURI] = isSupported;
238
239 return ("" + isSupported).toLowerCase();
240 }
241
242
243 /**
244 * Returns whether a given audio API exists or not (without keeping into account whether it is supported or not). All existing ones are defined in {@link CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS}.
245 * @function
246 * @param {string} audioAPI - The audio API that we want to check. All existing ones are defined in {@link CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS}. For example: "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
247 * @param {boolean} [sanitize=true] - If set to true, the "audioAPI" given will be trimmed and converted to upper case.
248 * @returns {boolean} Returns whether the given audio API exists or not (without keeping into account whether it is supported or not).
249 */
250 CB_AudioDetector.APIExists = function(audioAPI, sanitize)
251 {
252 if (typeof(sanitize) === "undefined" || sanitize === null) { sanitize = true; }
253 if (sanitize) { audioAPI = CB_trim(audioAPI).toUpperCase(); }
254 return (CB_indexOf(CB_Configuration[CB_BASE_NAME].CB_AudioFileCache_PREFERRED_AUDIO_APIS, audioAPI) !== -1);
255 }
256
257
258 CB_AudioDetector._getPreferredAPIReturnCache = {};
259 /**
260 * Calculates and returns the preferred audio API (from an array if it is given) for the current client, if any.
261 * @function
262 * @param {array} [audioAPIs=CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS] - An array of strings with the audio APIs that we want to check, in order of preference. All existing ones are defined in {@link CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS}. For example: "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
263 * @param {boolean} [allowEmulation=!!CB_Configuration[CB_BASE_NAME].CB_AudioDetector_allowEmulation_DEFAULT] - If set to true, it will also detect as supported emulated audio APIs (as "WAAPI" using [waapisim.js]{@link https://github.com/g200kg/WAAPISim} instead of supported natively).
264 * @param {boolean} [returnOnEmpty=undefined] - If set to true and no audio API is supported, it will return the value of this parameter instead of null.
265 * @returns {string|*} Returns a string with the preferred audio API (from an array if it is given) for the current client, if any. If no audio API is supported, it will return the value set in the "returnOnEmpty" parameter.
266 */
267 CB_AudioDetector.getPreferredAPI = function(audioAPIs, allowEmulation, returnOnEmpty)
268 {
269 audioAPIs = CB_AudioDetector.getSupportedAPIs(audioAPIs, allowEmulation);
270
271 if (allowEmulation !== true &amp;&amp; allowEmulation !== false) { allowEmulation = !!CB_Configuration[CB_BASE_NAME].CB_AudioDetector_allowEmulation_DEFAULT; }
272
273 //If it is not the first time, returns the same as the first time (from the cache):
274 if (typeof(CB_AudioDetector._getPreferredAPIReturnCache[audioAPIs]) !== "undefined" &amp;&amp; CB_AudioDetector._getPreferredAPIReturnCache[audioAPIs] !== null)
275 {
276 if (typeof(CB_AudioDetector._getPreferredAPIReturnCache[audioAPIs][allowEmulation]) !== "undefined" &amp;&amp; CB_AudioDetector._getPreferredAPIReturnCache[audioAPIs][allowEmulation] !== null)
277 {
278 return CB_AudioDetector._getPreferredAPIReturnCache[audioAPIs][allowEmulation];
279 }
280 else if (CB_AudioDetector._getPreferredAPIReturnCache[audioAPIs][allowEmulation] === null)
281 {
282 return returnOnEmpty;
283 }
284 }
285 else
286 {
287 CB_AudioDetector._getPreferredAPIReturnCache[audioAPIs] = {};
288 }
289
290 var preferredAPI = null;
291
292 if (audioAPIs.length > 0) { preferredAPI = audioAPIs[0]; }
293
294 //Stores the result in the cache for the next time:
295 CB_AudioDetector._getPreferredAPIReturnCache[audioAPIs][allowEmulation] = preferredAPI;
296
297 if (preferredAPI === null) { preferredAPI = returnOnEmpty; }
298
299 return preferredAPI;
300 }
301
302
303 CB_AudioDetector._getSupportedAPIsReturnCache = {};
304 /**
305 * Calculates and returns an array with the audio APIs supported (from an array if it is given) for the current client, if any.
306 * @function
307 * @param {array} [audioAPIs=CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS] - An array of strings with the audio APIs that we want to check. All existing ones are defined in {@link CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS}. For example: "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
308 * @param {boolean} [allowEmulation=!!CB_Configuration[CB_BASE_NAME].CB_AudioDetector_allowEmulation_DEFAULT] - If set to true, it will also detect as supported emulated audio APIs (as "WAAPI" using [waapisim.js]{@link https://github.com/g200kg/WAAPISim} instead of supported natively).
309 * @returns {array} Returns an array with the audio APIs supported (from an array if it is given) for the current client, if any. If no audio API is supported, an empty array will be returned.
310 */
311 CB_AudioDetector.getSupportedAPIs = function(audioAPIs, allowEmulation)
312 {
313 //If not given any APIs, uses the default ones with the default order:
314 if (typeof(audioAPIs) === "undefined" || audioAPIs === null || !CB_isArray(audioAPIs)) { audioAPIs = CB_Configuration[CB_BASE_NAME].CB_AudioFileCache_PREFERRED_AUDIO_APIS; }
315
316 if (allowEmulation !== true &amp;&amp; allowEmulation !== false) { allowEmulation = !!CB_Configuration[CB_BASE_NAME].CB_AudioDetector_allowEmulation_DEFAULT; }
317
318 //If it is not the first time, returns the same as the first time (from the cache):
319 if (typeof(CB_AudioDetector._getSupportedAPIsReturnCache[audioAPIs]) !== "undefined" &amp;&amp; CB_AudioDetector._getSupportedAPIsReturnCache[audioAPIs] !== null)
320 {
321 if (typeof(CB_AudioDetector._getSupportedAPIsReturnCache[audioAPIs][allowEmulation]) !== "undefined" &amp;&amp; CB_AudioDetector._getSupportedAPIsReturnCache[audioAPIs][allowEmulation] !== null)
322 {
323 return CB_AudioDetector._getSupportedAPIsReturnCache[audioAPIs][allowEmulation];
324 }
325 }
326 else
327 {
328 CB_AudioDetector._getSupportedAPIsReturnCache[audioAPIs] = {};
329 }
330
331
332 var supportedAudioAPIs = [];
333
334 var audioAPIsLength = audioAPIs.length;
335 for (var x = 0; x &lt; audioAPIsLength; x++)
336 {
337 if (CB_AudioDetector.isAPISupported(audioAPIs[x], allowEmulation))
338 {
339 if (CB_indexOf(supportedAudioAPIs, audioAPIs[x]) === -1)
340 {
341 supportedAudioAPIs[supportedAudioAPIs.length] = audioAPIs[x];
342 }
343 }
344 }
345
346 //Stores the result in the cache for the next time:
347 CB_AudioDetector._getSupportedAPIsReturnCache[audioAPIs][allowEmulation] = supportedAudioAPIs;
348
349 return supportedAudioAPIs;
350 }
351
352
353 CB_AudioDetector._isAPISupportedReturnCache = {};
354 /**
355 * Tells whether a given audio API is supported or not by the current client.
356 * @function
357 * @param {string} audioAPI - The audio API that we want to check. All existing ones are defined in {@link CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS}. For example: "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
358 * @param {boolean} [allowEmulation=!!CB_Configuration[CB_BASE_NAME].CB_AudioDetector_allowEmulation_DEFAULT] - If set to true, it will detect as supported also emulated audio APIs (as "WAAPI" using [waapisim.js]{@link https://github.com/g200kg/WAAPISim} instead of supported natively).
359 * @returns {boolean} Returns whether the given audio API is supported or not.
360 * @todo Have into account allowEmulation and detect whether emulation is being used if so (for example, detect whether [waapisim.js]{@link https://github.com/g200kg/WAAPISim} is being used).
361 */
362 CB_AudioDetector.isAPISupported = function(audioAPI, allowEmulation)
363 {
364 audioAPI = CB_trim(audioAPI).toUpperCase();
365
366 if (allowEmulation !== true &amp;&amp; allowEmulation !== false) { allowEmulation = !!CB_Configuration[CB_BASE_NAME].CB_AudioDetector_allowEmulation_DEFAULT; }
367
368 //If it is not the first time, returns the same as the first time (from the cache):
369 if (typeof(CB_AudioDetector._isAPISupportedReturnCache[audioAPI]) !== "undefined" &amp;&amp; CB_AudioDetector._isAPISupportedReturnCache[audioAPI] !== null)
370 {
371 if (typeof(CB_AudioDetector._isAPISupportedReturnCache[audioAPI][allowEmulation]) !== "undefined" &amp;&amp; CB_AudioDetector._isAPISupportedReturnCache[audioAPI][allowEmulation] !== null)
372 {
373 return CB_AudioDetector._isAPISupportedReturnCache[audioAPI][allowEmulation];
374 }
375 }
376 else
377 {
378 CB_AudioDetector._isAPISupportedReturnCache[audioAPI] = {};
379 }
380
381 var isSupported = false;
382
383 //TODO: Have into account allowEmulation and detect whether emulation is being used if so (for example, detect whether waapisim.js is being used).
384
385 //Detects whether it is supported or not:
386 if (audioAPI === "WAAPI") //Web Audio API.
387 {
388 isSupported = (allowEmulation || !CB_AudioDetector.isWAAPIUsingEmulation()) &amp;&amp; (typeof(window.AudioContext) !== "undefined" || typeof(window.webkitAudioContext) !== "undefined");
389 }
390 else if (audioAPI === "ACMP") //Apache Cordova Media Plugin.
391 {
392 isSupported = (typeof(Media) !== "undefined");
393 }
394 else if (audioAPI === "AAPI") //Audio API.
395 {
396 isSupported = (typeof(window.Audio) !== "undefined");
397 }
398 else if (audioAPI === "SM2") //SoundManager 2.
399 {
400 //SM2 needs either Audio API or Flash:
401 isSupported = CB_soundManager2Supported &amp;&amp; (CB_AudioDetector.isAPISupported("AAPI", false) || CB_AudioDetector.isSM2UsingFlash() &amp;&amp; CB_Client.supportsFlash());
402 }
403
404 //Stores the result in the cache for the next time:
405 CB_AudioDetector._isAPISupportedReturnCache[audioAPI][allowEmulation] = isSupported;
406
407 return isSupported;
408 }
409
410
411 /**
412 * Tells whether "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}) is using emulation (through [WAAPISim]{@link https://github.com/g200kg/WAAPISim}) or not.
413 * @function
414 * @returns {boolean} Returns whether "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}) is using emulation (through [WAAPISim]{@link https://github.com/g200kg/WAAPISim}) or not.
415 */
416 CB_AudioDetector.isWAAPIUsingEmulation = function()
417 {
418 return CB_Configuration[CB_BASE_NAME].WAAPISIM_LOAD;
419 }
420
421
422 /**
423 * Tells whether [SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/} is using [Adobe Flash (formerly Macromedia Flash)]{@link https://en.wikipedia.org/wiki/Adobe_Flash_Player} to emulate sound or not.
424 * @function
425 * @returns {boolean} Returns whether [SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/} is using [Adobe Flash (formerly Macromedia Flash)]{@link https://en.wikipedia.org/wiki/Adobe_Flash_Player} to emulate sound or not.
426 */
427 CB_AudioDetector.isSM2UsingFlash = function()
428 {
429 return (typeof(soundManager) !== "undefined" &amp;&amp; soundManager !== null &amp;&amp; typeof(soundManager.html5) !== "undefined" &amp;&amp; soundManager.html5 !== null &amp;&amp; soundManager.html5.usingFlash);
430 }
431
432
433} //End of the static class CB_AudioDetector.</pre>
434 </article>
435</section>
436
437
438
439
440
441 </div>
442 </div>
443
444 <div class="clearfix"></div>
445
446
447
448</div>
449</div>
450
451
452 <div class="modal fade" id="searchResults">
453 <div class="modal-dialog">
454 <div class="modal-content">
455 <div class="modal-header">
456 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
457 <h4 class="modal-title">Search results</h4>
458 </div>
459 <div class="modal-body"></div>
460 <div class="modal-footer">
461 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
462 </div>
463 </div><!-- /.modal-content -->
464 </div><!-- /.modal-dialog -->
465 </div>
466
467
468<footer>
469
470
471 <span class="copyright">
472 <a href="printable/" target="_blank">See a more printer-friendly version</a><hr /><span style="color:#000000">© <address style="display:inline; font-style:normal;"><a href="https://crossbrowdy.com/" target="_blank">CrossBrowdy</a> API documentation</address> by <a href="https://joanalbamaldonado.com/" target="_blank">Joan Alba Maldonado</a> - <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank">Creative Commons Attribution 4.0 International</a><br />DocStrap Copyright © 2012-2015 The contributors to the JSDoc3 and DocStrap projects.</span>
473 </span>
474
475<span class="jsdoc-message">
476 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
477
478 on Mon Feb 3rd 2020
479
480 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
481</span>
482</footer>
483
484<script src="scripts/docstrap.lib.js"></script>
485<script src="scripts/toc.js"></script>
486
487 <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
488
489
490<script>
491$( function () {
492 $( "[id*='$']" ).each( function () {
493 var $this = $( this );
494
495 $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
496 } );
497
498 $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
499 var $this = $( this );
500
501 var example = $this.find( "code" );
502 exampleText = example.html();
503 var lang = /{@lang (.*?)}/.exec( exampleText );
504 if ( lang && lang[1] ) {
505 exampleText = exampleText.replace( lang[0], "" );
506 example.html( exampleText );
507 lang = lang[1];
508 } else {
509 var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
510 lang = langClassMatch ? langClassMatch[1] : "javascript";
511 }
512
513 if ( lang ) {
514
515 $this
516 .addClass( "sunlight-highlight-" + lang )
517 .addClass( "linenums" )
518 .html( example.html() );
519
520 }
521 } );
522
523 Sunlight.highlightAll( {
524 lineNumbers : true,
525 showMenu : true,
526 enableDoclinks : true
527 } );
528
529 $.catchAnchorLinks( {
530 navbarOffset: 10
531 } );
532 $( "#toc" ).toc( {
533 anchorName : function ( i, heading, prefix ) {
534 return $( heading ).attr( "id" ) || ( prefix + i );
535 },
536 selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
537 showAndHide : false,
538 smoothScrolling: true
539 } );
540
541 $( "#main span[id^='toc']" ).addClass( "toc-shim" );
542 $( '.dropdown-toggle' ).dropdown();
543
544 $( "table" ).each( function () {
545 var $this = $( this );
546 $this.addClass('table');
547 } );
548
549} );
550</script>
551
552
553
554<!--Navigation and Symbol Display-->
555
556<script>
557 $( function () {
558 $( '#main' ).localScroll( {
559 offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
560 } );
561 $( "dt.name" ).each( function () {
562 var $this = $( this ).find("h4");
563 var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
564 var dt = $(this);
565 var children = dt.next( "dd" );
566
567 dt.prepend( icon ).css( {cursor : "pointer"} );
568 dt.addClass( "member-collapsed" ).addClass( "member" );
569
570
571 children.hide();
572
573 dt.children().on( "click", function () {
574 children = dt.next( "dd" );
575 children.slideToggle( "fast", function () {
576
577 if ( children.is( ":visible" ) ) {
578 icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
579 dt.addClass( "member-open" ).animate( "member-collapsed" );
580 } else {
581 icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
582 dt.addClass( "member-collapsed" ).removeClass( "member-open" );
583 }
584 } );
585 } );
586
587 } );
588 } );
589</script>
590
591
592<!--Google Analytics-->
593
594
595
596 <script type="text/javascript">
597 $(document).ready(function() {
598 SearcherDisplay.init();
599 });
600 </script>
601
602
603</body>
604</html>