UNPKG

129 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_AudioFileSpritesPool.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_AudioFileSpritesPool.js</h1>
83
84<section>
85 <article>
86 <pre
87 class="sunlight-highlight-javascript linenums">/**
88 * @file Audio sprites pool management. Contains the {@link CB_AudioFileSpritesPool} 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 * Object whose property names the identifiers of each sprite (a case-sensitive string) and their value is a {@link CB_AudioFileSprites.DATA_OBJECT} object.
96 * @example
97 * {
98 * "sprites_group_id_1" : CB_AudioFileSprites.DATA_OBJECT,
99 * "sprites_group_id_2" : CB_AudioFileSprites.DATA_OBJECT,
100 * "sprites_group_id_3" : CB_AudioFileSprites.DATA_OBJECT,
101 * ...
102 * }
103 * @memberof CB_AudioFileSpritesPool
104 * @typedef {Object} CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT
105 * @property {CB_AudioFileSprites.DATA_OBJECT} spritesGroupId - Being the name of each property the unique identifier of a sprites group which will use a future internally-created {@link CB_AudioFileSprites} object, the value will always be the {@link CB_AudioFileSprites.DATA_OBJECT} that the {@link CB_AudioFileSprites} object will use to be created (received by its constructor). Some of the missing properties ("preferredAPIs", "preferredFormats", "minimumAudioFiles", "maximumAudioFiles", "minimumAudioFilesFree", "newAudioFilesWhenNeeded", "retries", "checkManually", "checkManuallyOnNeededCreated", "checkManuallyOnPlayingFailed", "checkManuallyOnCheckingFailed" and "disableAutoLoad") will use the value set on the properties of the main {@link CB_AudioFileSpritesPool.DATA_OBJECT} object (if any) used by the {@link CB_AudioFileSpritesPool} object. If a function in the "onError" parameter is given, it will always be wrapped so the main error function set on the {@link CB_AudioFileSpritesPool#onError} parameter will always be called (if any) through the {@link CB_AudioFileSpritesPool#errorFunction} method.
106 */
107
108
109/**
110 * Object with the desired data and options for the audio sprites. It is almost identical to the {@link CB_AudioFileSprites.DATA_OBJECT} but adding a "spritesGroups" property.
111 * @memberof CB_AudioFileSpritesPool
112 * @typedef {Object} CB_AudioFileSpritesPool.DATA_OBJECT
113 * @property {CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} [spritesGroups] - Object with the desired sprites groups, containing the {@link CB_AudioFileSprites.DATA_OBJECT} objects which will be used to create the {@link CB_AudioFileSprites} objects internally. Each group will have a {@link CB_AudioFileSprites} object. It will be used as the first parameter to call the {@link CB_AudioFileSpritesPool#insertSpritesGroups} method internally. Some of the missing properties ("preferredAPIs", "preferredFormats", "minimumAudioFiles", "maximumAudioFiles", "minimumAudioFilesFree", "newAudioFilesWhenNeeded", "retries", "checkManually", "checkManuallyOnNeededCreated", "checkManuallyOnPlayingFailed", "checkManuallyOnCheckingFailed" and "disableAutoLoad") of the {@link CB_AudioFileSprites.DATA_OBJECT} objects given will use the value set on the other properties of this object (if any).
114 * @property {string} [id=""] - Desired identifier for the object. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#id} property.
115 * @property {array} [preferredAPIs={@link CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS}] - Array of strings with the preferred audio API or audio APIs, in order of preference. 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 try to calculate and use the best one for the current client. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#preferredAPIs} property. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "preferredAPIs" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
116 * @property {array} [preferredFormats={@link CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_FORMATS}] - Array of strings with the preferred 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"'), in order of preference. It will try to calculate and use the best one for the current client. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#preferredFormats} property. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "preferredFormats" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
117 * @property {integer} [minimumAudioFiles={@link CB_AudioFileCache.minimumAudioFiles_DEFAULT}] - Minimum {@link CB_AudioFile} objects to create internally. It must be an integer being 1 the minimum. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#minimumAudioFiles} property. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "minimumAudioFiles" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
118 * @property {integer} [maximumAudioFiles={@link CB_AudioFileCache.maximumAudioFiles_DEFAULT}] - Maximum {@link CB_AudioFile} objects that are to be created internally. If it is set to null, there will not be a maximum (it will be unlimited). If an integer is provided, it must be the same number or greater than the value set in the {@link CB_AudioFileCache#minimumAudioFiles} property (also provided by the "minimumAudioFiles" of this object), allowing 1 minimum. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#maximumAudioFiles} property. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "maximumAudioFiles" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
119 * @property {integer} [minimumAudioFilesFree=parseInt({@link CB_AudioFileCache#minimumAudioFiles} * 0.25 + 0.5)] - New {@link CB_AudioFile} objects will be created internally when the number of free {@link CB_AudioFile} objects reaches this limit. If provided, it must be an integer being 0 (zero) the minimum. It will end using a 25% of the {@link CB_AudioFileSpritesPool#minimumAudioFiles} by default, rounded to ceil, allowing 0 (zero) minimum. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#minimumAudioFilesFree} property. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "minimumAudioFilesFree" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
120 * @property {integer} [newAudioFilesWhenNeeded=Math.min(parseInt({@link CB_AudioFileCache#minimumAudioFiles} * 0.1 + 0.5), 1)] - Number of new {@link CB_AudioFile} objects to create internally when the minimum limit of free {@link CB_AudioFile} objects ({@link CB_AudioFileSpritesPool#minimumAudioFilesFree}) is reached. If provided, it must be an integer being 0 (zero) the minimum. It will end using a 10% of the {@link CB_AudioFileSpritesPool#minimumAudioFiles} by default, rounded to ceil, allowing 1 minimum. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#newAudioFilesWhenNeeded} property. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "newAudioFilesWhenNeeded" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
121 * @property {integer} [retries={@link CB_AudioFileCache.retries_DEFAULT}] - Number of retries to try to load a {@link CB_AudioFile} object internally before trying to load the next possible one internally (if any). It must be an integer being 0 the minimum. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#retries} property. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "retries" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
122 * @property {boolean} [checkManually={@link CB_AudioFileCache.checkManually_DEFAULT}] - Tells whether the {@link CB_AudioFile} objects must be checked automatically or not (manually) by default. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#checkManually} property. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "checkManually" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
123 * @property {boolean} [checkManuallyOnNeededCreated={@link CB_AudioFileCache.checkManuallyOnNeededCreated_DEFAULT}] - Tells whether the {@link CB_AudioFile} objects must be checked automatically or not (manually) when creates a new {@link CB_AudioFile} object needed. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#checkManuallyOnNeededCreated} property. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "checkManuallyOnNeededCreated" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
124 * @property {boolean} [checkManuallyOnPlayingFailed={@link CB_AudioFileCache.checkManuallyOnPlayingFailed_DEFAULT}] - Tells whether the {@link CB_AudioFile} objects must be checked automatically or not (manually) when playing one has failed and tries to reload it. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#checkManuallyOnPlayingFailed} property. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "checkManuallyOnPlayingFailed" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
125 * @property {boolean} [checkManuallyOnCheckingFailed={@link CB_AudioFileCache.checkManuallyOnCheckingFailed_DEFAULT}] - Tells whether the {@link CB_AudioFile} objects must be checked automatically or not (manually) when checking one has failed and tries to reload it. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#checkManuallyOnCheckingFailed} property. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "checkManuallyOnCheckingFailed" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
126 * @property {function} [onLoad] - Desired function to be called once the pool has been loaded. The first and unique parameter will be an integer with the {@link CB_AudioFile} objects that still need to be checked, if any, being "this" the current {@link CB_AudioFileSpritesPool} object. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#onLoad} property.
127 * @property {function} [onError] - Desired function to be called when any kind of error happens. The first and unique parameter will be a string with the error description (if it could be determined), being "this" the current {@link CB_AudioFileSpritesPool} object. If a valid value is given, this will be added to the {@link CB_AudioFileSpritesPool#onError} property. If a function is set, it will always be called through the {@link CB_AudioFileSpritesPool#errorFunction} method whenever the "onError" event of an internally-created {@link CB_AudioFileSprites} object is fired.
128 * @property {boolean} [disableAutoLoad=false] - If set to true, it will not create automatically the {@link CB_AudioFile} objects by calling the {@link CB_AudioFileCache#createAudioFiles} method internally. Internal usage only recommended. If the {@link CB_AudioFileSprites.DATA_OBJECT} object (defined in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object set in the "spritesGroups") of a certain sprites group does not contain the "disableAutoLoad" property, it will use the value of this property instead when creating its {@link CB_AudioFileSprites} object internally.
129 */
130
131
132/**
133 * The constructor is recommended to be called through a user-driven event (as onClick, onTouch, etc.), as some clients may need this at least the first time in order to be able to play the audio.
134 * @class
135 * @classdesc Class to manage many audio sprites stored in different groups, each with one {@link CB_AudioFileSprites} object (used internally).
136 * @param {CB_AudioFileSpritesPool.DATA_OBJECT} [dataObject] - Object with the desired data and options for the groups of audio sprites. Each group will have a {@link CB_AudioFileSprites} object. Some of its properties ("preferredAPIs", "preferredFormats", "minimumAudioFiles", "maximumAudioFiles", "minimumAudioFilesFree", "newAudioFilesWhenNeeded", "retries", "checkManually", "checkManuallyOnNeededCreated", "checkManuallyOnPlayingFailed", "checkManuallyOnCheckingFailed" and "disableAutoLoad") will be used as the default value to create internally the {@link CB_AudioFileSprites} objects when the value is not given in the {@link CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} object (set as the value of the {@link CB_AudioFileSpritesPool.DATA_OBJECT#spritesGroups} property).
137 * @returns {CB_AudioFileSpritesPool} Returns a new {@link CB_AudioFileSpritesPool} object.
138 * @todo Do not allow to create one object with an "id" which has already been used (unless the value is undefined, null...).
139 * @todo Method getCopy and static method filterProperties (similar to the ones from {@link CB_GraphicSprites} and {@link CB_GraphicSpritesScene}).
140 */
141var CB_AudioFileSpritesPool = function(dataObject)
142{
143 //Creates an instance of this object and returns it in the case that it is being called from an unexpected context:
144 if (this === window || !(this instanceof CB_AudioFileSpritesPool)) { return new CB_AudioFileSpritesPool(dataObject); }
145
146 //Properties and variables:
147 /**
148 * Stores the identifier for the audio file sprites pool object.
149 * @var
150 * @readonly
151 * @type {string}
152 * @default
153 */
154 this.id = "";
155
156 /**
157 * Stores an array of strings with the preferred audio API or audio APIs, in order of preference. 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}). Internal usage only recommended.
158 * @var
159 * @readonly
160 * @type {array}
161 * @default CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS
162 */
163 this.preferredAPIs = undefined;
164
165 /**
166 * Stores an array of strings with the preferred 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"'), in order of preference. Internal usage only recommended.
167 * @var
168 * @readonly
169 * @type {array}
170 * @default CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_FORMATS
171 */
172 this.preferredFormats = undefined;
173
174 /**
175 * Minimum {@link CB_AudioFile} objects to create internally for each {@link CB_AudioFileSprites} object. It must be an integer being 1 the minimum. Internal usage only recommended.
176 * @var
177 * @readonly
178 * @type {integer}
179 * @default CB_AudioFileCache.minimumAudioFiles_DEFAULT
180 */
181 this.minimumAudioFiles = undefined;
182
183 /**
184 * Maximum {@link CB_AudioFile} objects that are to be created internally for each {@link CB_AudioFileSprites} object. If it is set to null, there will not be a maximum (it will be unlimited). If an integer is provided, it must be the same number or greater than the value set in the {@link CB_AudioFileCache#minimumAudioFiles} property, allowing 1 minimum. Internal usage only recommended.
185 * @var
186 * @readonly
187 * @type {integer|null}
188 * @default CB_AudioFileCache.maximumAudioFiles_DEFAULT
189 */
190 this.maximumAudioFiles = undefined;
191
192 /**
193 * New {@link CB_AudioFile} objects will be created internally for each {@link CB_AudioFileSprites} object when the number of free {@link CB_AudioFile} objects reaches this limit. It must be an integer being 0 (zero) the minimum. Internal usage only recommended.
194 * @var
195 * @readonly
196 * @type {integer}
197 * @default parseInt({@link CB_AudioFileCache#minimumAudioFiles} * 0.25 + 0.5)
198 */
199 this.minimumAudioFilesFree = undefined;
200
201 /**
202 * Number of new {@link CB_AudioFile} objects to create internally for each {@link CB_AudioFileSprites} object when the minimum limit of free {@link CB_AudioFile} objects ({@link CB_AudioFileCache#minimumAudioFilesFree}) is reached. It must be an integer being 0 (zero) the minimum. Internal usage only recommended.
203 * @var
204 * @readonly
205 * @type {integer}
206 * @default Math.min(parseInt({@link CB_AudioFileCache#minimumAudioFiles} * 0.1 + 0.5), 1)
207 */
208 this.newAudioFilesWhenNeeded = undefined;
209
210 /**
211 * Number of retries to try to load a {@link CB_AudioFile} object internally before trying to load the next possible one internally (if any). It must be an integer being 0 the minimum. Internal usage only recommended.
212 * @var
213 * @readonly
214 * @type {integer}
215 * @default CB_AudioFileCache.retries_DEFAULT
216 */
217 this.retries = undefined;
218
219
220 /**
221 * Tells whether the {@link CB_AudioFile} objects must be checked automatically or not (manually). Internal usage only recommended.
222 * @var
223 * @readonly
224 * @type {boolean}
225 * @default CB_AudioFileCache.checkManually_DEFAULT
226 */
227 this.checkManually = undefined;
228
229 /**
230 * Tells whether the {@link CB_AudioFile} objects must be checked automatically or not (manually) when creates a new {@link CB_AudioFile} object needed. Internal usage only recommended.
231 * @var
232 * @readonly
233 * @type {boolean}
234 * @default CB_AudioFileCache.checkManuallyOnNeededCreated_DEFAULT
235 */
236 this.checkManuallyOnNeededCreated = undefined;
237
238 /**
239 * Tells whether the {@link CB_AudioFile} objects must be checked automatically or not (manually) when playing one has failed and tries to reload it. Internal usage only recommended.
240 * @var
241 * @readonly
242 * @type {boolean}
243 * @default CB_AudioFileCache.checkManuallyOnPlayingFailed_DEFAULT
244 */
245 this.checkManuallyOnPlayingFailed = undefined;
246
247 /**
248 * Tells whether the {@link CB_AudioFile} objects must be checked automatically or not (manually) when checking one has failed and tries to reload it. Internal usage only recommended.
249 * @var
250 * @readonly
251 * @type {boolean}
252 * @default CB_AudioFileCache.checkManuallyOnCheckingFailed_DEFAULT
253 */
254 this.checkManuallyOnCheckingFailed = undefined;
255
256 /**
257 * If set to true, it will not create automatically the {@link CB_AudioFile} objects by calling the {@link CB_AudioFileCache#createAudioFiles} method internally. Internal usage only recommended.
258 * @var
259 * @readonly
260 * @type {boolean}
261 * @default false
262 */
263 this.disableAutoLoad = undefined;
264
265 /**
266 * Desired function to be called once the pool has been loaded. The first and unique parameter will be an integer with the {@link CB_AudioFile} objects that still need to be checked, if any, being "this" the current {@link CB_AudioFileSpritesPool} object.
267 * @var
268 * @readonly
269 * @type {function}
270 * @default
271 */
272 this.onLoad = undefined;
273
274 /**
275 * Desired function to be called when any kind of error happens. The first and unique parameter will be a string with the error description (if it could be determined), being "this" the current {@link CB_AudioFileSpritesPool} object. If a function is set, it will always be called through the {@link CB_AudioFileSpritesPool#errorFunction} method whenever the "onError" event of an internally-created {@link CB_AudioFileSprites} object is fired.
276 * @var
277 * @readonly
278 * @type {function}
279 * @default
280 */
281 this.onError = undefined; //Function to call if not all AudioFiles can be loaded.
282
283 /**
284 * Stores the internally-created {@link CB_AudioFileSprites} objects, using the name of each property as their group ID and the value being the {@link CB_AudioFileSprites} object itself. Internal usage only recommended.
285 * @var
286 * @readonly
287 * @type {Object}
288 * @default
289 */
290 this.audioFileSprites = {}; //Object with the CB_AudioFileSprites objects.
291
292
293 //Internal properties:
294 this._aborted = false;
295 this._checkSpritesGroupsLoadedTimeout = null;
296 this._checkPlayingAllInterval;
297 this._checkPlayingAllPerforming = false;
298 this._setAudioAPIAllInterval;
299 this._setAudioAPIAllPerforming = false;
300 this._errorFunctionExecuted = false;
301
302
303 //Calls the constructor of the object when creates an instance:
304 return this._init(dataObject);
305}
306
307
308//Static properties and constants:
309/**
310 * Status value for audio file sprites pool which is unloaded. Can be used to compare the value returned by the {@link CB_AudioFileSpritesPool#getStatus} method. Recommended for internal usage only.
311 * @constant
312 * @type {integer}
313 * @default 0
314 */
315CB_AudioFileSpritesPool.UNLOADED = 0; //Status value for unloaded cache.
316
317/**
318 * Status value for an audio file sprites pool which is loading. Can be used to compare the value returned by the {@link CB_AudioFileSpritesPool#getStatus} method. Recommended for internal usage only.
319 * @constant
320 * @type {integer}
321 * @default
322 */
323CB_AudioFileSpritesPool.LOADING = 1; //Status value for loading cache.
324
325/**
326 * Status value for an audio file sprites pool which has not been checked yet. Can be used to compare the value returned by the {@link CB_AudioFileSpritesPool#getStatus} method. Recommended for internal usage only.
327 * @constant
328 * @type {integer}
329 * @default
330 */
331CB_AudioFileSpritesPool.UNCHECKED = 2; //STatus value for an unchecked cache.
332
333/**
334 * Status value for an audio file sprites pool which is being checked currently. Can be used to compare the value returned by the {@link CB_AudioFileSpritesPool#getStatus} method. Recommended for internal usage only.
335 * @constant
336 * @type {integer}
337 * @default
338 */
339CB_AudioFileSpritesPool.CHECKING = 3; //Status value for checking a cache.
340
341/**
342 * Status value for an audio file sprites pool which has been loaded. Can be used to compare the value returned by the {@link CB_AudioFileSpritesPool#getStatus} method. Recommended for internal usage only.
343 * @constant
344 * @type {integer}
345 * @default
346 */
347CB_AudioFileSpritesPool.LOADED = 4; //Status value for loaded cache.
348
349/**
350 * Status value for an audio file sprites pool which failed to be loaded or failed for any other reason. Can be used to compare the value returned by the {@link CB_AudioFileSpritesPool#getStatus} method. Recommended for internal usage only.
351 * @constant
352 * @type {integer}
353 * @default
354 */
355CB_AudioFileSpritesPool.FAILED = 5; //Status value for failed to load cache.
356
357/**
358 * Status value for an audio file sprites pool which has been aborted. This will happen when the audio file sprites pool has been destroyed with the {@link CB_AudioFileSpritesPool#destructor} method. Can be used to compare the value returned by the {@link CB_AudioFileSpritesPool#getStatus} method. Recommended for internal usage only.
359 * @constant
360 * @type {integer}
361 * @default
362 */
363CB_AudioFileSpritesPool.ABORTED = 6; //Status value for aborted cache.
364
365
366//Constructor:
367CB_AudioFileSpritesPool.prototype._init = function(dataObject)
368{
369 /*
370 FORMAT:
371 dataObject =
372 {
373 [id : String,]
374 [onLoad : Function,]
375 [onError : Function,]
376
377 [preferredAPIs : Array&lt;String>,]
378 [preferredFormats : Array&lt;String>,]
379 [minimumAudioFiles : Integer,]
380 [maximumAudioFiles : Integer,]
381 [minimumAudioFilesFree : Integer,]
382 [newAudioFilesWhenNeeded : Integer,]
383 [retries : Integer,]
384 [checkManually : Boolean,]
385 [checkManuallyOnNeededCreated : Boolean,]
386 [checkManuallyOnPlayingFailed : Boolean,]
387 [checkManuallyOnCheckingFailed : Boolean,]
388 [disableAutoLoad : Boolean,]
389
390 spritesGroups :
391 {
392 "sprites_group_id" : CB_AudioFileSprites.DATA_OBJECT
393 [, ...]
394 }
395 };
396 */
397
398 //Tries to load the data (if any):
399 this.load(dataObject);
400
401 //Returns the object:
402 return this;
403}
404
405
406/**
407 * Destroys the audio file sprites pool object (removing all sprites, etc.), including the internal audio file sprites objects, and frees memory. By default, unless the "preventAbortedStatus" is set to true, sets the current status of all the {@link CB_AudioFileCache} objects as ABORTED ({@link CB_AudioFileCache.ABORTED} value). Internally, calls the {@link CB_AudioFileSprites#destructor} method of all the internally-created {@link CB_AudioFileSprites} objects.
408 * @function
409 * @param {boolean} [stopSounds=false] - Used as the "stopSounds" parameter when calling internally the {@link CB_AudioFileSprites#destructor} method of all the internally-created {@link CB_AudioFileSprites} objects.
410 * @param {boolean} [preventAbortedStatus=false] - If set to true (not recommended), it will not assign the status of "ABORTED" (it will not set the {@link CB_AudioFileSpritesPool#_aborted} property to true}. Used as the "preventAbortedStatus" parameter when calling internally the {@link CB_AudioFileSprites#destructor} method of all the internally-created {@link CB_AudioFileSprites} objects.
411 */
412CB_AudioFileSpritesPool.prototype.destructor = function(stopSounds, preventAbortedStatus)
413{
414 clearInterval(this._checkPlayingAllInterval);
415 clearInterval(this._setAudioAPIAllInterval);
416 clearTimeout(this._checkSpritesGroupsLoadedTimeout);
417
418 //Destroys the CB_AudioFileSprites objects:
419 for (var audioFileSpritesObject in this.audioFileSprites)
420 {
421 this.audioFileSprites[audioFileSpritesObject].destructor(stopSounds, preventAbortedStatus);
422 }
423
424 //Resets properties to their default value:
425 this.preferredAPIs = undefined;
426 this.preferredFormats = undefined;
427 this.minimumAudioFiles = undefined;
428 this.maximumAudioFiles = undefined;
429 this.minimumAudioFilesFree = undefined;
430 this.newAudioFilesWhenNeeded = undefined;
431 this.retries = undefined;
432 this.checkManually = undefined;
433 this.checkManuallyOnNeededCreated = undefined;
434 this.checkManuallyOnPlayingFailed = undefined;
435 this.checkManuallyOnCheckingFailed = undefined;
436 this.disableAutoLoad = undefined;
437 this.onLoad = undefined;
438 this.onError = undefined;
439 this.audioFileSprites = {};
440
441 if (!preventAbortedStatus) { this._aborted = true; }
442}
443
444
445/**
446 * Loads the audio file sprites pool with the desired data given. This method is called by the constructor automatically. Recommended to be called through a user-driven event (as onClick, onTouch, etc.), as some clients may need this at least the first time in order to be able to play the audio.
447 * @function
448 * @param {CB_AudioFileSpritesPool.DATA_OBJECT} dataObject - Object with the desired data and options for the audio file sprites.
449 * @returns {CB_AudioFileSpritesPool|null} If a "dataObject" is given, it returns the current {@link CB_AudioFileSpritesPool} object. Otherwise, it returns null.
450 */
451CB_AudioFileSpritesPool.prototype.load = function(dataObject)
452{
453 if (typeof(dataObject) === "undefined" || dataObject === null) { return null; }
454
455 //Destroys all previous data (if any):
456 this.destructor(true, true); //Also stops all sounds.
457 this._aborted = false;
458
459 //Sanitizes the given data:
460 dataObject.id = CB_trim(dataObject.id);
461
462 //Sets the new data:
463 if (dataObject.id !== "") { this.id = dataObject.id; }
464 if (typeof(dataObject.preferredAPIs) !== "undefined") { this.preferredAPIs = dataObject.preferredAPIs; }
465 if (typeof(dataObject.preferredFormats) !== "undefined") { this.preferredFormats = dataObject.preferredFormats; }
466 if (typeof(dataObject.minimumAudioFiles) !== "undefined") { this.minimumAudioFiles = dataObject.minimumAudioFiles; }
467 if (typeof(dataObject.maximumAudioFiles) !== "undefined") { this.maximumAudioFiles = dataObject.maximumAudioFiles; }
468 if (typeof(dataObject.minimumAudioFilesFree) !== "undefined") { this.minimumAudioFilesFree = dataObject.minimumAudioFilesFree; }
469 if (typeof(dataObject.newAudioFilesWhenNeeded) !== "undefined") { this.newAudioFilesWhenNeeded = dataObject.newAudioFilesWhenNeeded; }
470 if (typeof(dataObject.retries) !== "undefined") { this.retries = dataObject.retries; }
471 if (typeof(dataObject.checkManually) !== "undefined") { this.checkManually = dataObject.checkManually; }
472 if (typeof(dataObject.checkManuallyOnNeededCreated) !== "undefined") { this.checkManuallyOnNeededCreated = dataObject.checkManuallyOnNeededCreated; }
473 if (typeof(dataObject.checkManuallyOnPlayingFailed) !== "undefined") { this.checkManuallyOnPlayingFailed = dataObject.checkManuallyOnPlayingFailed; }
474 if (typeof(dataObject.checkManuallyOnCheckingFailed) !== "undefined") { this.checkManuallyOnCheckingFailed = dataObject.checkManuallyOnCheckingFailed; }
475 if (typeof(dataObject.disableAutoLoad) !== "undefined") { this.disableAutoLoad = dataObject.disableAutoLoad; }
476
477 if (typeof(dataObject.onLoad) !== "undefined") { this.onLoad = dataObject.onLoad; }
478 if (typeof(dataObject.onError) !== "undefined") { this.onError = dataObject.onError; }
479
480 //Inserts the CB_AudioFileSprites objects:
481 if (typeof(dataObject.spritesGroups) !== "undefined" &amp;&amp; dataObject.spritesGroups !== null)
482 {
483 this.removeSpritesGroups();
484 this.insertSpritesGroups(dataObject.spritesGroups);
485 }
486
487 return this;
488}
489
490
491//Checks whether all CB_AudioFileSprites objects are loaded or not:
492CB_AudioFileSpritesPool.prototype._checkSpritesGroupsLoaded = function()
493{
494 clearTimeout(this._checkSpritesGroupsLoadedTimeout);
495
496 var allLoaded = true;
497 var x;
498 for (var audioFileSpritesObject in this.audioFileSprites)
499 {
500 x++;
501 if (!this.audioFileSprites[audioFileSpritesObject].audioFileCache.checkManually &amp;&amp; this.audioFileSprites[audioFileSpritesObject].getStatus() !== CB_AudioFileCache.LOADED)
502 {
503 allLoaded = false;
504 break;
505 }
506 else if (this.audioFileSprites[audioFileSpritesObject].audioFileCache.checkManually &amp;&amp; this.audioFileSprites[audioFileSpritesObject].getStatus() !== CB_AudioFileCache.UNCHECKED &amp;&amp; this.audioFileSprites[audioFileSpritesObject].getStatus() !== CB_AudioFileCache.LOADED)
507 {
508 allLoaded = false;
509 break;
510 }
511 }
512 if (x === 0) { allLoaded = false; }
513
514 var that = this;
515
516 if (this.getStatus() === CB_AudioFileSpritesPool.LOADING || this.getStatus() === CB_AudioFileSpritesPool.UNCHECKED)
517 {
518 if (!allLoaded) { this._checkSpritesGroupsLoadedTimeout = setTimeout(function() { that._checkSpritesGroupsLoaded.call(that); }, 100); }
519 else
520 {
521 if (typeof(this.onLoad) === "function")
522 {
523 var objectsNeedChecking = 0;
524 var audioFiles;
525 var audioFilesLength;
526 var x;
527 for (var audioFileSpritesObject in this.audioFileSprites)
528 {
529 audioFiles = this.audioFileSprites[audioFileSpritesObject].getAudioFiles(false);
530 audioFilesLength = audioFiles.length;
531 for (x = 0; x &lt; audioFilesLength; x++) { if (audioFiles[x].getStatus() === CB_AudioFile.UNCHECKED) { objectsNeedChecking++; } }
532 }
533 this.onLoad.call(this, objectsNeedChecking);
534 }
535 }
536 }
537}
538
539
540/**
541 * Removes all the sprites groups ({@link CB_AudioFileSprites} objects) by clearing the {@link CB_AudioFileSpritesPool#audioFileSprites} property.
542 * @function
543 */
544CB_AudioFileSpritesPool.prototype.removeSpritesGroups = function()
545{
546 this.audioFileSprites = {};
547}
548
549
550/**
551 * Inserts the given sprites groups.
552 * @function
553 * @param {CB_AudioFileSpritesPool.SPRITES_GROUPS_OBJECT} sprites - Object with the desired sprites groups.
554 * @returns {integer} Returns the number of sprites groups inserted.
555 */
556CB_AudioFileSpritesPool.prototype.insertSpritesGroups = function(spritesGroups)
557{
558 var inserted = 0;
559 var that = this;
560 if (typeof(spritesGroups) !== "undefined" &amp;&amp; spritesGroups !== null)
561 {
562 clearTimeout(this._checkSpritesGroupsLoadedTimeout);
563
564 for (var spritesGroupId in spritesGroups)
565 {
566 //Inserts the sprite:
567 if (this.insertSpritesGroup(spritesGroupId, spritesGroups[spritesGroupId], true)) { inserted++; }
568 }
569
570 this._checkSpritesGroupsLoadedTimeout = setTimeout(function() { that._checkSpritesGroupsLoaded.call(that); }, 100);
571 }
572 return inserted;
573}
574
575
576/**
577 * Inserts the given sprites group to the audio file sprites pool object.
578 * @function
579 * @param {string} spritesGroupId - The identifier for the sprites group.
580 * @param {CB_AudioFileSprites.DATA_OBJECT} [dataObject] - Object with the data of the sprites group. Optional but recommended.
581 * @param {boolean} [avoidCheckingLoaded=false] - If set to true, it will not check whether all sprites groups has been loaded after inserting the desired one. This is done internally by the {@link CB_AudioFileSpritesPool#_checkSpritesGroupsLoaded} method which will fire the {@link CB_AudioFileSpritesPool#onLoad} function (if any).
582 * @returns {boolean} Returns true if the sprites group has been inserted or false otherwise.
583 */
584CB_AudioFileSpritesPool.prototype.insertSpritesGroup = function(spritesGroupId, dataObject, avoidCheckingLoaded)
585{
586 if (typeof(spritesGroupId) === "undefined" || spritesGroupId === null) { return false; }
587
588 if (typeof(dataObject) === "undefined" || dataObject === null) { dataObject = {}; }
589
590 if (avoidCheckingLoaded)
591 {
592 clearTimeout(this._checkSpritesGroupsLoadedTimeout);
593 }
594
595 var dataObjectCopy = {};
596 dataObjectCopy.id = spritesGroupId;
597 dataObjectCopy.preferredAPIs = dataObject.preferredAPIs;
598 dataObjectCopy.preferredFormats = dataObject.preferredFormats;
599 dataObjectCopy.URIs = dataObject.URIs;
600 dataObjectCopy.minimumAudioFiles = dataObject.minimumAudioFiles;
601 dataObjectCopy.maximumAudioFiles = dataObject.maximumAudioFiles;
602 dataObjectCopy.minimumAudioFilesFree = dataObject.minimumAudioFilesFree;
603 dataObjectCopy.newAudioFilesWhenNeeded = dataObject.newAudioFilesWhenNeeded;
604 dataObjectCopy.retries = dataObject.retries;
605 dataObjectCopy.checkManually = dataObject.checkManually;
606 dataObjectCopy.checkManuallyOnNeededCreated = dataObject.checkManuallyOnNeededCreated;
607 dataObjectCopy.checkManuallyOnPlayingFailed = dataObject.checkManuallyOnPlayingFailed;
608 dataObjectCopy.checkManuallyOnCheckingFailed = dataObject.checkManuallyOnCheckingFailed;
609 dataObjectCopy.disableAutoLoad = dataObject.disableAutoLoad;
610 dataObjectCopy.onLoad = dataObject.onLoad;
611 dataObjectCopy.onError = dataObject.onError;
612 dataObjectCopy.sprites = dataObject.sprites;
613
614 if (typeof(dataObjectCopy.preferredAPIs) === "undefined" &amp;&amp; typeof(this.preferredAPIs) !== "undefined") { dataObjectCopy.preferredAPIs = this.preferredAPIs; }
615 if (typeof(dataObjectCopy.preferredFormats) === "undefined" &amp;&amp; typeof(this.preferredFormats) !== "undefined") { dataObjectCopy.preferredFormats = this.preferredFormats; }
616 if (typeof(dataObjectCopy.minimumAudioFiles) === "undefined" &amp;&amp; typeof(this.minimumAudioFiles) !== "undefined") { dataObjectCopy.minimumAudioFiles = this.minimumAudioFiles; }
617 if (typeof(dataObjectCopy.maximumAudioFiles) === "undefined" &amp;&amp; typeof(this.maximumAudioFiles) !== "undefined") { dataObjectCopy.maximumAudioFiles = this.maximumAudioFiles; }
618 if (typeof(dataObjectCopy.minimumAudioFilesFree) === "undefined" &amp;&amp; typeof(this.minimumAudioFilesFree) !== "undefined") { dataObjectCopy.minimumAudioFilesFree = this.minimumAudioFilesFree; }
619 if (typeof(dataObjectCopy.newAudioFilesWhenNeeded) === "undefined" &amp;&amp; typeof(this.newAudioFilesWhenNeeded) !== "undefined") { dataObjectCopy.newAudioFilesWhenNeeded = this.newAudioFilesWhenNeeded; }
620 if (typeof(dataObjectCopy.retries) === "undefined" &amp;&amp; typeof(this.retries) !== "undefined") { dataObjectCopy.retries = this.retries; }
621 if (typeof(dataObjectCopy.checkManually) === "undefined" &amp;&amp; typeof(this.checkManually) !== "undefined") { dataObjectCopy.checkManually = this.checkManually; }
622 if (typeof(dataObjectCopy.checkManuallyOnNeededCreated) === "undefined" &amp;&amp; typeof(this.checkManuallyOnNeededCreated) !== "undefined") { dataObjectCopy.checkManuallyOnNeededCreated = this.checkManuallyOnNeededCreated; }
623 if (typeof(dataObjectCopy.checkManuallyOnPlayingFailed) === "undefined" &amp;&amp; typeof(this.checkManuallyOnPlayingFailed) !== "undefined") { dataObjectCopy.checkManuallyOnPlayingFailed = this.checkManuallyOnPlayingFailed; }
624 if (typeof(dataObjectCopy.checkManuallyOnCheckingFailed) === "undefined" &amp;&amp; typeof(this.checkManuallyOnCheckingFailed) !== "undefined") { dataObjectCopy.checkManuallyOnCheckingFailed = this.checkManuallyOnCheckingFailed; }
625 if (typeof(dataObjectCopy.disableAutoLoad) === "undefined" &amp;&amp; typeof(this.disableAutoLoad) !== "undefined") { dataObjectCopy.disableAutoLoad = this.disableAutoLoad; }
626
627 //Wraps the error function:
628 var that = this;
629 var onErrorOld = dataObjectCopy.onError;
630 dataObjectCopy.onError =
631 function(error)
632 {
633 if (typeof(onErrorOld) === "function") { onErrorOld.call(this, error); }
634 setTimeout(function() { that.errorFunction.call(that, error); }, 100);
635 };
636
637 this._errorFunctionExecuted = false; //Allows the execution of the error function again.
638
639 this.audioFileSprites[spritesGroupId] = new CB_AudioFileSprites(dataObjectCopy);
640
641 if (!avoidCheckingLoaded)
642 {
643 this._checkSpritesGroupsLoadedTimeout = setTimeout(function() { that._checkSpritesGroupsLoaded.call(that); }, 100);
644 }
645
646 return true;
647}
648
649
650/**
651 * Removes a sprites group by its ID.
652 * @function
653 * @param {string} spritesGroupId - The identifier for the sprites group.
654 * @param {boolean} [destroy=false] - If set to true, it will call the {@link CB_AudioFileSprites#destructor} method of the {@link CB_AudioFileSprites} object which belongs to the desired sprites group.
655 * @param {boolean} [stopSounds=false] - If the "destroy" parameter is set to false, this parameter will be ignored. Used as the "stopSound" parameter when calling internally the {@link CB_AudioFileSprites#destructor} method of the {@link CB_AudioFileSprites} object which belongs to the desired sprites group.
656 * @param {boolean} [preventAbortedStatus=false] - If the "destroy" parameter is set to false, this parameter will be ignored. Used as the "preventAbortedStatus" parameter when calling internally the {@link CB_AudioFileSprites#destructor} method of the {@link CB_AudioFileSprites} object which belongs to the desired sprites group.
657 * @returns {boolean} Returns true if the sprites group has been deleted or false otherwise.
658 */
659CB_AudioFileSpritesPool.prototype.removeSpritesGroup = function(spritesGroupId, destroy, stopSounds, preventAbortedStatus)
660{
661 if (typeof(this.audioFileSprites[spritesGroupId]) !== "undefined" &amp;&amp; this.audioFileSprites[spritesGroupId] !== null)
662 {
663 if (destroy)
664 {
665 this.audioFileSprites[spritesGroupId].destructor(stopSounds, preventAbortedStatus);
666 }
667 this.audioFileSprites[spritesGroupId] = null;
668
669 var audioFileSprites = {};
670 for (spritesGroupId in this.audioFileSprites)
671 {
672 if (typeof(this.audioFileSprites[spritesGroupId]) !== "undefined" &amp;&amp; this.audioFileSprites[spritesGroupId] !== null)
673 {
674 audioFileSprites[spritesGroupId] = this.audioFileSprites[spritesGroupId];
675 }
676 }
677 this.audioFileSprites = audioFileSprites;
678 return true;
679 }
680 return false;
681}
682
683
684/**
685 * Returns a sprites group (the {@link CB_AudioFileSprites} object) by its ID.
686 * @function
687 * @param {string} spritesGroupId - The identifier for the sprites group.
688 * @param {boolean} [withoutChecking=false] - If set to true and the sprites group cannot be found, the method will return undefined (or whatever is stored by the given ID) instead of null.
689 * @returns {CB_AudioFileSprites|undefined|*|null} Returns null if the "withoutChecking" parameter is set to true and the sprites group cannot be found. Otherwise, it will return what is stored internally by the given ID which can be a {@link CB_AudioFileSprites} object if found or undefined (or whatever is stored by the given ID) if not found.
690 */
691CB_AudioFileSpritesPool.prototype.getSpritesGroup = function(spritesGroupId, withoutChecking)
692{
693 //return this.audioFileSprites[spritesGroupId];
694 if (typeof(this.audioFileSprites[spritesGroupId]) !== "undefined" || withoutChecking)
695 {
696 return this.audioFileSprites[spritesGroupId];
697 }
698 return null;
699}
700
701
702/**
703 * Returns an object with the sprites groups (all the internally-created {@link CB_AudioFileSprites} objects), being the name of each property their group ID and the value being the {@link CB_AudioFileSprites} object itself. Internally, it just returns the {@link CB_AudioFileSpritesPool#audioFileSprites} property.
704 * @function
705 * @returns {Object} Returns an object with the sprites groups (all the internally-created {@link CB_AudioFileSprites} objects), being the name of each property their group ID and the value being the {@link CB_AudioFileSprites} object itself. Internally, it just returns the {@link CB_AudioFileSpritesPool#audioFileSprites} property.
706 */
707CB_AudioFileSpritesPool.prototype.getSpritesGroups = function()
708{
709 return this.audioFileSprites;
710}
711
712
713/**
714 * Returns an object with the sprites (and includes "_WITHOUT_SPRITE_ASSOCIATED" if we want to). Internally, uses the {@link CB_AudioFileSprites#getSprites} method.
715 * @function
716 * @param {boolean} [includeWithoutSpriteAssociated=false] - If set to true, the returning object will also contain a property called "_WITHOUT_SPRITE_ASSOCIATED" whose value will be an empty object (unless the "orderBySpritesGroup" parameter is set to true and the property existed before in the object stored in the {@link CB_AudioFileSprites#sprites} property and had a value which is not an empty object). If set to false and the "orderBySpritesGroup" parameter is also set to false, the returning object will not contain the "_WITHOUT_SPRITE_ASSOCIATED" property. If set to false and the "orderBySpritesGroup" parameter is set to true, the returning object will not contain the "_WITHOUT_SPRITE_ASSOCIATED" property unless the property existed before in the object stored in the {@link CB_AudioFileSprites#sprites} property.
717 * @param {boolean} [orderBySpritesGroup=false] - If set to false, it will return a {@link CB_AudioFileSprites.SPRITES_OBJECT} object whose properties will be the ID of each sprite (each sprite ID should be unique) and their value will be a {@link CB_AudioFileSprites.SPRITE_OBJECT} object. If set to true, it will return an object whose properties will be the ID of each sprites group and the value will be a {@link CB_AudioFileSprites.SPRITES_OBJECT} object which will include its sprites.
718 * @returns {CB_AudioFileSprites.SPRITES_OBJECT|Object} If the "orderBySpritesGroup" is set to false, it will return a {@link CB_AudioFileSprites.SPRITES_OBJECT} object whose properties will be the ID of each sprite (each sprite ID should be unique) and their value will be a {@link CB_AudioFileSprites.SPRITE_OBJECT} object. If the "orderBySpritesGroup" is set to true, it will return an object whose properties will be the ID of each sprites group and the value will be a {@link CB_AudioFileSprites.SPRITES_OBJECT} object which will include its sprites.
719 */
720CB_AudioFileSpritesPool.prototype.getSprites = function(includeWithoutSpriteAssociated, orderBySpritesGroup)
721{
722 var sprites = {};
723
724 if (!orderBySpritesGroup)
725 {
726 if (includeWithoutSpriteAssociated) { sprites["_WITHOUT_SPRITE_ASSOCIATED"] = {}; }
727 var spritesLoop;
728 var spriteId;
729 for (var spritesGroupId in this.audioFileSprites)
730 {
731 spritesLoop = this.audioFileSprites[spritesGroupId].getSprites(false);
732 for (spriteId in spritesLoop)
733 {
734 sprites[spriteId] = spritesLoop[spriteId];
735 }
736 }
737 }
738 else
739 {
740 for (var spritesGroupId in this.audioFileSprites)
741 {
742 sprites[spritesGroupId] = this.audioFileSprites[spritesGroupId].getSprites(includeWithoutSpriteAssociated);
743 }
744 }
745
746 return sprites;
747}
748
749
750/**
751 * Returns the sound instances (their ID) used (stored in the {@link CB_AudioFileSprites#spriteSoundInstances} property of each {@link CB_AudioFileSprites} object).
752 * @function
753 * @param {boolean} [oneDimension=false] - If set to false, it will return an object whose property names will be the ID of each sprites group and their value will be the {@link CB_AudioFileSprites#spriteSoundInstances} property of each {@link CB_AudioFileSprites} object (which includes the "_WITHOUT_SPRITE_ASSOCIATED" property for sound instances without a sprite associated) which belongs to that sprites group. Otherwise, if it is set to true, it will return a numeric array whose values are the sound instance IDs.
754 * @param {boolean} [includeWithoutSpriteAssociated=false] - If set to true, it will also return the sound instance identifiers which are not associated to any sprite. Used as the "includeWithoutSpriteAssociated" parameter when calling the {@link CB_AudioFileSprites#getSoundInstancesId} method internally. Only used when the "oneDimension" parameter is set to true.
755 * @returns {Object|array} Returns the sound instances (their ID) used (stored in the {@link CB_AudioFileSprites#spriteSoundInstances} property). If the "oneDimension" parameter is set to false, it will return an object whose property names will be the ID of each sprites group and their value will be the {@link CB_AudioFileSprites#spriteSoundInstances} property of each {@link CB_AudioFileSprites} object (which includes the "_WITHOUT_SPRITE_ASSOCIATED" property for sound instances without a sprite associated) which belongs to that sprites group. If the "oneDimension" parameter is set to true, it will return a numeric array whose values are the sound instance identifiers (if the "includeWithoutSpriteAssociated" parameter it set to true, it will also include the sound instances which are not associated to any sprite).
756 */
757CB_AudioFileSpritesPool.prototype.getSoundInstancesId = function(oneDimension, includeWithoutSpriteAssociated)
758{
759 var soundInstances;
760 if (!oneDimension)
761 {
762 soundInstances = {};
763 for (var spritesGroupId in this.audioFileSprites)
764 {
765 soundInstances[spritesGroupId] = this.audioFileSprites[spritesGroupId].getSoundInstancesId(false, includeWithoutSpriteAssociated);
766 }
767 }
768 else
769 {
770 soundInstances = [];
771 var soundInstancesSpritesGroup;
772 var soundInstancesSpritesGroupLength;
773 var y = 0;
774 var x = 0;
775 for (var spritesGroupId in this.audioFileSprites)
776 {
777 soundInstancesSpritesGroup = this.audioFileSprites[spritesGroupId].getSoundInstancesId(true, includeWithoutSpriteAssociated);
778 soundInstancesSpritesGroupLength = soundInstancesSpritesGroup.length;
779 for (x = 0; x &lt; soundInstancesSpritesGroupLength; x++)
780 {
781 soundInstances[y++] = soundInstancesSpritesGroup[x];
782 }
783 }
784 }
785 return soundInstances;
786}
787
788
789/**
790 * Object returned by the {@link CB_AudioFileSpritesPool#getAudioFilesUsed} method. Each property names will be the the ID of each sprites group and their value will be a {@link CB_AudioFileSprites.getAudioFilesUsed_OBJECT} object.
791 * @memberof CB_AudioFileSpritesPool
792 * @typedef {Object} CB_AudioFileSpritesPool.getAudioFilesUsed_OBJECT
793 * @property {CB_AudioFileSpritesPool.getAudioFilesUsed_OBJECT} spriteId - Each property names will be the the ID of each sprites group and their value will be a {@link CB_AudioFileSprites.getAudioFilesUsed_OBJECT} object.
794 */
795
796/**
797 * Returns the {@link CB_AudioFile} objects used by all the sounds instances of all the sprites groups.
798 * @function
799 * @param {boolean} [oneDimension=false] - If set to false, it will return an object whose property names will be the ID of each sprites group and their value will be the an object whose property names are the sprite identifiers (including the "_WITHOUT_SPRITE_ASSOCIATED" property for sound instances without a sprite associated, if the "includeWithoutSpriteAssociated" is set to true) and their value will be a numeric array with the {@link CB_AudioFile} objects used. Otherwise, if set to true, it will return a numeric array with the {@link CB_AudioFile} objects used (if the "includeWithoutSpriteAssociated" parameter is set to true, it will also contain the {@link CB_AudioFile} objects whose sound instance ID is not associated to any sprite).
800 * @param {boolean} [includeWithoutSpriteAssociated=false] - If set to true, it will also return the {@link CB_AudioFile} objects whose sound instance ID is not associated to any sprite. Used as the "includeWithoutSpriteAssociated" parameter when calling the {@link CB_AudioFileSprites#getAudioFilesUsed} method internally.
801 * @param {boolean} [avoidCancelled=false] - If set to true, it will not return the {@link CB_AudioFile} objects whose sound instance has been cancelled. Used as the "avoidCancelled" parameter when calling the {@link CB_AudioFileSprites#getAudioFilesUsed} method internally.
802 * @returns {CB_AudioFileSprites.getAudioFilesUsed_OBJECT|array} Returns the {@link CB_AudioFile} objects used by all the sounds instances of all the sprites groups. If the "oneDimension" parameter is set to false, it will return a {@link CB_AudioFileSpritesPool.getAudioFilesUsed_OBJECT} object whose property names will be the ID of each sprites group and their value will be a {@link CB_AudioFileSprites.getAudioFilesUsed_OBJECT} object whose property names are the sprite identifiers (including the "_WITHOUT_SPRITE_ASSOCIATED" property for sound instances without a sprite associated, if the "includeWithoutSpriteAssociated" is set to true) and their value will be a numeric array with the {@link CB_AudioFile} objects used. Otherwise, if the "oneDimension" parameter set to true, it will return a numeric array with the {@link CB_AudioFile} objects used (if the "includeWithoutSpriteAssociated" parameter is set to true, it will also contain the {@link CB_AudioFile} objects whose sound instance ID is not associated to any sprite).
803 */
804CB_AudioFileSpritesPool.prototype.getAudioFilesUsed = function(oneDimension, includeWithoutSpriteAssociated, avoidCancelled)
805{
806 var audioFiles;
807 if (!oneDimension)
808 {
809 audioFiles = {};
810 for (var spritesGroupId in this.audioFileSprites)
811 {
812 audioFiles[spritesGroupId] = this.audioFileSprites[spritesGroupId].getAudioFilesUsed(false, includeWithoutSpriteAssociated, avoidCancelled);
813 }
814 }
815 else
816 {
817 audioFiles = [];
818 var audioFilesSpritesGroup;
819 var audioFilesSpritesGroupLength;
820 var y = 0;
821 var x = 0;
822 for (var spritesGroupId in this.audioFileSprites)
823 {
824 audioFilesSpritesGroup = this.audioFileSprites[spritesGroupId].getAudioFilesUsed(true, includeWithoutSpriteAssociated, avoidCancelled);
825 audioFilesSpritesGroupLength = audioFilesSpritesGroup.length;
826 for (x = 0; x &lt; audioFilesSpritesGroupLength; x++)
827 {
828 audioFiles[y++] = audioFilesSpritesGroup[x];
829 }
830 }
831 }
832 return audioFiles;
833}
834
835
836/**
837 * Callback that is used when finishes all iterations after looping through the items. Being "this" an array with all the items.
838 * @memberof CB_AudioFileSpritesPool
839 * @callback CB_AudioFileSpritesPool.executeFunctionAll_ON_FINISH_CALLBACK
840 * @param {array} array - An array with all the items which were being looped.
841 * @param {integer} itemsAffected - The number of times that the "functionEach" callback was called (the most likely, matches the number of elements unless they are undefined or null).
842 * @param {integer} delayMaximum - The maximum "delay" used.
843 */
844
845/**
846 * Alias for {@link CB_AudioFileSpritesPool#executeFunctionAllSprites}.
847 * @function CB_AudioFileSpritesPool#executeAllSprites
848 * @see {@link CB_AudioFileSpritesPool#executeFunctionAllSprites}
849 */
850 /**
851 * Alias for {@link CB_AudioFileSpritesPool#executeFunctionAllSprites}.
852 * @function CB_AudioFileSpritesPool#forEachSprite
853 * @see {@link CB_AudioFileSpritesPool#executeFunctionAllSprites}
854 */
855/**
856 * Executes a desired function for all the {@link CB_AudioFile} objects used by all the sound instances currently created of each sprite group. It calls the {@link CB_AudioFileSprites#executeFunctionAllSprites} method internally.
857 * @function
858 * @param {CB_Arrays.executeFunctionAll_ON_LOOP_CALLBACK} functionEach - Used as the "functionEach" parameter when calling the {@link CB_AudioFileSprites#executeFunctionAllSprites} method internally.
859 * @param {number|CB_Arrays.executeFunctionAll_ON_LOOP_CALLBACK} [delayBetweenEach=0] - Used as the "delayBetweenEach" parameter when calling the {@link CB_AudioFileSprites#executeFunctionAllSprites} method internally. Note that each call to the {@link CB_AudioFileSprites#executeFunctionAllSprites} method will be performed sequentially one after the other, without adding a delay.
860 * @param {boolean} [includeWithoutSpriteAssociated=false] - Used as the "includeWithoutSpriteAssociated" parameter when calling the {@link CB_AudioFileSprites#executeFunctionAllSprites} method internally.
861 * @param {boolean} [avoidCancelled=false] - Used as the "avoidCancelled" parameter when calling the {@link CB_AudioFileSprites#executeFunctionAllSprites} method internally.
862 * @param {boolean} [delayBetweenEachAffectsFirst=false] - Used as the "delayBetweenEachAffectsFirst" parameter when calling the {@link CB_AudioFileSprites#executeFunctionAllSprites} method internally. Internal usage only recommended. Note that each call to the {@link CB_AudioFileSprites#executeFunctionAllSprites} method will be performed sequentially one after the other, without adding a delay.
863 * @param {CB_AudioFileSpritesPool.executeFunctionAll_ON_FINISH_CALLBACK} [functionFinish] - Function that will be called for when it has finished looping all the items. The first parameter will be the array containing all the items which were looped, the second parameter will be the number of times that the "functionEach" callback was called (the most likely, matches the number of elements unless they are undefined or null), and the third parameter will be the maximum "delay" used, being "this" the array itself.
864 * @returns {integer} It will return the number of calls to the "functionEach" function that were performed (which should be the same number as the {@link CB_AudioFile} objects used by the sound instances that belong to the sprites of each sprites group). Note that if a value greater than 0 (zero) for the "delayBetweenEach" parameter has been provided, perhaps not all calls of the "functionEach" function will have been performed yet when exiting this method because of the asynchronous nature of the [setTimeout]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout} function.
865 * @todo Think about implementing a "returnSetTimeoutsArray" or similar (as in {@link CB_AudioFileSprites#executeFunctionAllSprites}).
866 * @todo Think about consider executing only one by one (now it will loop {@link CB_AudioFile} objects from different sprites groups simultaneously).
867 */
868CB_AudioFileSpritesPool.prototype.executeFunctionAllSprites = CB_AudioFileSpritesPool.prototype.executeAllSprites = CB_AudioFileSpritesPool.prototype.forEachSprite = function(functionEach, delayBetweenEach, includeWithoutSpriteAssociated, avoidCancelled, delayBetweenEachAffectsFirst, functionFinish)
869{
870 var spritesGroups = 0;
871 for (var spritesGroupId in this.audioFileSprites) { spritesGroups++; } //Counts the number of sprites groups.
872 var functionFinishLoopTimes = 0;
873 var functionFinishLoop = function(array, itemsAffected, delay)
874 {
875 functionFinishLoopTimes++;
876 for (var x = 0; x &lt; itemsAffected.length; x++) { arrayAllItems[arrayAllItems.length] = itemsAffected[x]; }
877 //If it is the last time, calls the finish function:
878 if (spritesGroups === functionFinishLoopTimes &amp;&amp; typeof(functionFinish) === "function") { functionFinish.call(arrayAllItems, arrayAllItems, performed, delay); }
879 };
880 var arrayAllItems = [];
881 var performed = 0;
882 for (var spritesGroupId in this.audioFileSprites)
883 {
884 performed += this.audioFileSprites[spritesGroupId].executeFunctionAllSprites(functionEach, delayBetweenEach, includeWithoutSpriteAssociated, avoidCancelled, false, delayBetweenEachAffectsFirst, functionFinishLoop); //The desired delay (if any) will only start affecting after the first call.
885 }
886 return performed;
887}
888
889
890/**
891 * Cleans the arrays of the {@link CB_AudioFile} objects (taking off the undefined or null ones) which is in the {@link CB_AudioFileCache#audioFiles} property used by each {@link CB_AudioFileSprites} object, just keeping the valid ones and clearing (destroying and removing) the others. For performance purposes. Uses the {@link CB_AudioFileSprites#clearAudioFiles} method internally. Internal usage only recommended.
892 * @function
893 * @param {boolean} [avoidCallingCheckCacheLoaded=false] - Used as the "avoidCallingCheckCacheLoaded" parameter when calling the {@link CB_AudioFileSprites#clearAudioFiles} method internally.
894 * @returns {array} Returns an object whose each property name is the sprites group ID and each value is the returning value of calling internally the {@link CB_AudioFileSprites#clearAudioFiles} method.
895 */
896CB_AudioFileSpritesPool.prototype.clearAudioFiles = function(avoidCallingCheckCacheLoaded)
897{
898 var audioFiles = {};
899 for (var spritesGroupId in this.audioFileSprites)
900 {
901 audioFiles[spritesGroupId] = this.audioFileSprites[spritesGroupId].clearAudioFiles(avoidCallingCheckCacheLoaded);
902 }
903 return audioFiles;
904}
905
906
907/**
908 * Tries to purge the audio file cache of each {@link CB_AudioFileSprites} object until it reaches a desired number of {@link CB_AudioFile} objects internally (set in the {@link CB_AudioFileCache#audioFiles} property), by removing and destroying some of the current {@link CB_AudioFile} objects. Note that the desired number is for each {@link CB_AudioFileSprites} object and not a global number. For performance purposes. Uses the {@link CB_AudioFileSprites#purge} method internally.
909 * @function
910 * @param {integer} desiredNumber - Used as the "desiredNumber" parameter when calling the {@link CB_AudioFileSprites#purge} method internally. Note that the desired number is for each {@link CB_AudioFileSprites} object and not a global number.
911 * @param {boolean} [setAsMinimumAudioFiles=false] - Used as the "setAsMinimumAudioFiles" parameter when calling the {@link CB_AudioFileSprites#purge} method internally.
912 * @param {boolean} [includePlaying=false] - Used as the "includePlaying" parameter when calling the {@link CB_AudioFileSprites#purge} method internally.
913 * @param {boolean} [stopSounds=false] - Used as the "stopSounds" parameter when calling the {@link CB_AudioFileSprites#purge} method internally.
914 * @param {array} [statuses=Array({@link CB_AudioFile.LOADING}, {@link CB_AudioFile.UNCHECKED}, {@link CB_AudioFile.CHECKING}, {@link CB_AudioFile.LOADED})] - Used as the "statuses" parameter when calling the {@link CB_AudioFileSprites#purge} method internally.
915 * @returns {integer} Returns the number of {@link CB_AudioFile} objects removed.
916 */
917CB_AudioFileSpritesPool.prototype.purge = function(desiredNumber, setAsMinimumAudioFiles, includePlaying, stopSounds, statuses)
918{
919 var objectsRemoved = 0;
920 for (var spritesGroupId in this.audioFileSprites)
921 {
922 objectsRemoved += this.audioFileSprites[spritesGroupId].purge(desiredNumber, setAsMinimumAudioFiles, includePlaying, stopSounds, statuses);
923 }
924 return objectsRemoved;
925}
926
927
928/**
929 * Tells whether a desired {@link CB_AudioFile} object is free (it is in the {@link CB_AudioFileCache#audioFilesFree} property of any {@link CB_AudioFileSprites} object) or not, by its identifier. A free {@link CB_AudioFile} object is an object which is not being used and it is available to be used. Uses the {@link CB_AudioFileSprites#isAudioFileFree} method internally.
930 * @function
931 * @param {string} id - Used as the "id" parameter when calling the {@link CB_AudioFileSprites#isAudioFileFree} method internally.
932 * @returns {boolean} Returns whether a desired {@link CB_AudioFile} object is free (it is in the {@link CB_AudioFileCache#audioFilesFree} property of any {@link CB_AudioFileSprites} object) or not, by its identifier. A free {@link CB_AudioFile} object is an object which is not being used and it is available to be used.
933 */
934CB_AudioFileSpritesPool.prototype.isAudioFileFree = function(id)
935{
936 for (var spritesGroupId in this.audioFileSprites)
937 {
938 if (this.audioFileSprites[spritesGroupId].isAudioFileFree(id)) { return true; }
939 }
940 return false;
941}
942
943
944/**
945 * Clears the sound instances (created by the {@link CB_AudioFileCache#play} method) which have been cancelled. Uses the {@link CB_AudioFileSprites#clearSoundInstances} method internally.
946 * @function
947 * @param {boolean} [clearWithObjectAssociated=false] - Used as the "clearWithObjectAssociated" parameter when calling the {@link CB_AudioFileSprites#clearSoundInstances} method internally.
948 * @returns {integer} Returns the number of cleared sound instances.
949 */
950CB_AudioFileSpritesPool.prototype.clearSoundInstances = function(clearWithObjectAssociated)
951{
952 var cleared = 0;
953 for (var spritesGroupId in this.audioFileSprites)
954 {
955 cleared += this.audioFileSprites[spritesGroupId].clearSoundInstances(clearWithObjectAssociated);
956 }
957 return cleared;
958}
959
960
961/**
962 * Cancels (to prevent they start playing) or enables all sound instances (created by the {@link CB_AudioFileCache#play} method). Uses the {@link CB_AudioFileSprites#cancelSoundInstances} method internally.
963 * @function
964 * @param {boolean} [cancel=false] - Used as the "cancel" parameter when calling the {@link CB_AudioFileSprites#cancelSoundInstances} method internally.
965 * @param {boolean} [affectWithObjectAssociated=false] - Used as the "affectWithObjectAssociated" parameter when calling the {@link CB_AudioFileSprites#cancelSoundInstances} method internally.
966 * @returns {integer} Returns the number of sound instances modified.
967 */
968CB_AudioFileSpritesPool.prototype.cancelSoundInstances = function(cancel, affectWithObjectAssociated)
969{
970 var performed = 0;
971 for (var spritesGroupId in this.audioFileSprites)
972 {
973 performed += this.audioFileSprites[spritesGroupId].cancelSoundInstances(cancel, affectWithObjectAssociated);
974 }
975 return performed;
976}
977
978
979/**
980 * Cancels (to prevent it starts playing) or enables a sound instance (created by the {@link CB_AudioFileCache#play} method), by its identifier. Uses the {@link CB_AudioFileSprites#cancelSoundInstance} method internally.
981 * @function
982 * @param {integer} soundInstanceId - Used as the "soundInstanceId" parameter when calling the {@link CB_AudioFileSprites#cancelSoundInstance} method internally.
983 * @param {boolean} [cancel=false] - Used as the "cancel" parameter when calling the {@link CB_AudioFileSprites#cancelSoundInstance} method internally.
984 * @param {boolean} [affectWithObjectAssociated=false] - Used as the "affectWithObjectAssociated" parameter when calling the {@link CB_AudioFileSprites#cancelSoundInstance} method internally.
985 * @returns {boolean} Returns true if the sound instance has been modified or false otherwise.
986 */
987CB_AudioFileSpritesPool.prototype.cancelSoundInstance = function(soundInstanceId, cancel, affectWithObjectAssociated)
988{
989 for (var spritesGroupId in this.audioFileSprites)
990 {
991 if (this.audioFileSprites[spritesGroupId].cancelSoundInstance(soundInstanceId, cancel, affectWithObjectAssociated)) { return true; }
992 }
993 return false;
994}
995
996
997/**
998 * Gets the {@link CB_AudioFile} object associated to a given sound instance ID (created by the {@link CB_AudioFileCache#play} method), if any, or null otherwise. Uses the {@link CB_AudioFileSprites#getAudioFileBySoundInstanceId} method internally.
999 * @function
1000 * @param {integer} soundInstanceId - Used as the "soundInstanceId" parameter when calling the {@link CB_AudioFileSprites#getAudioFileBySoundInstanceId} method internally.
1001 * @param {boolean} [avoidCancelled=false] - Used as the "avoidCancelled" parameter when calling the {@link CB_AudioFileSprites#getAudioFileBySoundInstanceId} method internally.
1002 * @returns {CB_AudioFile|null} Returns the {@link CB_AudioFile} object associated to a given sound instance ID, if any, or null otherwise.
1003 */
1004CB_AudioFileSpritesPool.prototype.getAudioFileBySoundInstanceId = function(soundInstanceId, avoidCancelled)
1005{
1006 var audioFile;
1007 for (var spritesGroupId in this.audioFileSprites)
1008 {
1009 audioFile = this.audioFileSprites[spritesGroupId].getAudioFileBySoundInstanceId(soundInstanceId, avoidCancelled);
1010 if (typeof(audioFile) !== "undefined" &amp;&amp; audioFile !== null) { return audioFile; }
1011 }
1012 return null;
1013}
1014
1015
1016/**
1017 * Alias for {@link CB_AudioFileSpritesPool#executeFunctionAll}.
1018 * @function CB_AudioFileSpritesPool#executeAll
1019 * @see {@link CB_AudioFileSpritesPool#executeFunctionAll}
1020 */
1021 /**
1022 * Alias for {@link CB_AudioFileSpritesPool#executeFunctionAll}.
1023 * @function CB_AudioFileSpritesPool#forEach
1024 * @see {@link CB_AudioFileSpritesPool#executeFunctionAll}
1025 */
1026/**
1027 * Performs a desired action, using the provided function, on all the existing {@link CB_AudioFile} objects or on the desired ones (if provided). Uses the {@link CB_AudioFileSprites#executeFunctionAll} method internally.
1028 * @function
1029 * @param {CB_Arrays.CB_Arrays.executeFunctionAll_ON_LOOP_CALLBACK} functionEach - Used as the "functionEach" parameter when calling the {@link CB_AudioFileSprites#executeFunctionAll} method internally.
1030 * @param {number|CB_Arrays.executeFunctionAll_ON_LOOP_CALLBACK} [delayBetweenEach=0] - Used as the "delayBetweenEach" parameter when calling the {@link CB_AudioFileSprites#executeFunctionAll} method internally. Note that each call to the {@link CB_AudioFileSprites#executeFunctionAll} method will be performed sequentially one after the other, without adding a delay.
1031 * @param {array} [audioFiles={@link CB_AudioFileCache#audioFiles}] - Used as the "audioFiles" parameter when calling the {@link CB_AudioFileSprites#executeFunctionAll} method internally.
1032 * @param {boolean} [returnArrayOfSetTimeoutsArray=false] - If it is set to false, it will return the number of calls to the "functionEach" function that were performed. Otherwise, if it is set to true, it will return a numeric array and each value (which will belong to each sprites group) will be another numeric array with a {@link CB_AudioFileCache.executeFunctionAll_OBJECT} object for each {@link CB_AudioFile} of that sprites group.
1033 * @param {boolean} [delayBetweenEachAffectsFirst=false] - Used as the "delayBetweenEachAffectsFirst" parameter when calling the {@link CB_AudioFileSprites#executeFunctionAll} method internally. Note that each call to the {@link CB_AudioFileSprites#executeFunctionAll} method will be performed sequentially one after the other, without adding a delay.
1034 * @param {CB_AudioFileSpritesPool.executeFunctionAll_ON_FINISH_CALLBACK} [functionFinish] - Function that will be called for when it has finished looping all the items. The first parameter will be the array containing all the items which were looped, the second parameter will be the number of times that the "functionEach" callback was called (the most likely, matches the number of elements unless they are undefined or null), and the third parameter will be the maximum "delay" used, being "this" the array itself.
1035 * @returns {integer|array} If the "returnArrayOfSetTimeoutsArray" parameter is set to false, it will return the number of calls to the "functionEach" function that were performed. Otherwise, if the "returnArrayOfSetTimeoutsArray" is set to true, it will return a numeric array and each value will be another numeric array with a {@link CB_AudioFileCache.executeFunctionAll_OBJECT} object for each {@link CB_AudioFile} given. Note that if a value greater than 0 (zero) for the "delayBetweenEach" parameter has been provided, perhaps not all calls of the "functionEach" function will have been performed yet when exiting this method because of the asynchronous nature of the [setTimeout]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout} function.
1036 * @todo Think about consider executing only one by one (now it will loop {@link CB_AudioFile} objects from different sprites groups simultaneously).
1037 */
1038CB_AudioFileSpritesPool.prototype.executeFunctionAll = CB_AudioFileSpritesPool.prototype.executeAll = CB_AudioFileSpritesPool.prototype.forEach = function(functionEach, delayBetweenEach, audioFiles, returnArrayOfSetTimeoutsArray, delayBetweenEachAffectsFirst, functionFinish)
1039{
1040 var spritesGroups = 0;
1041 for (var spritesGroupId in this.audioFileSprites) { spritesGroups++; } //Counts the number of sprites groups.
1042 var functionFinishLoopTimes = 0;
1043 var functionFinishLoop = function(array, itemsAffected, delay)
1044 {
1045 functionFinishLoopTimes++;
1046 for (var x = 0; x &lt; itemsAffected.length; x++) { arrayAllItems[arrayAllItems.length] = itemsAffected[x]; }
1047 //If it is the last time, calls the finish function:
1048 if (spritesGroups === functionFinishLoopTimes &amp;&amp; typeof(functionFinish) === "function") { functionFinish.call(arrayAllItems, arrayAllItems, performed, delay); }
1049 };
1050 var arrayAllItems = [];
1051
1052 if (returnArrayOfSetTimeoutsArray)
1053 {
1054 var arrayOfSetTimeoutsObjects = [];
1055 for (var spritesGroupId in this.audioFileSprites)
1056 {
1057 arrayOfSetTimeoutsObjects[arrayOfSetTimeoutsObjects.length] = this.audioFileSprites[spritesGroupId].executeFunctionAll(functionEach, delayBetweenEach, audioFiles, true, delayBetweenEachAffectsFirst, functionFinishLoop); //The desired delay (if any) will only start affecting after the first call.
1058 }
1059 return arrayOfSetTimeoutsObjects;
1060 }
1061 else
1062 {
1063 var performed = 0;
1064 for (var spritesGroupId in this.audioFileSprites)
1065 {
1066 performed += this.audioFileSprites[spritesGroupId].executeFunctionAll(functionEach, delayBetweenEach, audioFiles, false, delayBetweenEachAffectsFirst, functionFinishLoop); //The desired delay (if any) will only start affecting after the first call.
1067 }
1068 return performed;
1069 }
1070}
1071
1072
1073/**
1074 * Destroys all the {@link CB_AudioFile} objects and frees memory, by calling {@link CB_AudioFile#destructor}(stopSounds, false, true). Uses the {@link CB_AudioFileSprites#destroyAll} method internally.
1075 * @function
1076 * @param {boolean} [stopSounds=false] - Used as the "stopSounds" parameter when calling the {@link CB_AudioFileSprites#destroyAll} method internally.
1077 * @returns {integer} Returns the number of {@link CB_AudioFile} objects whose {@link CB_AudioFile#destructor} has been called.
1078 */
1079CB_AudioFileSpritesPool.prototype.destroyAll = function(stopSounds)
1080{
1081 var destroyed = 0;
1082 for (var spritesGroupId in this.audioFileSprites)
1083 {
1084 destroyed += this.audioFileSprites[spritesGroupId].destroyAll(stopSounds);
1085 }
1086 return destroyed;
1087}
1088
1089
1090/**
1091 * Callback function used by the {@link CB_AudioFileSpritesPool#checkPlayingAll} method that will be called when all the process was performed successfully.
1092 * @memberof CB_AudioFileSpritesPool
1093 * @callback CB_AudioFileSpritesPool.checkPlayingAll_CALLBACK_OK
1094 * @param {integer} performedActions - The number of {@link CB_AudioFile} objects that can be played.
1095 * @param {integer} uncheckedObjects - The number of {@link CB_AudioFile} objects that needed to be checked before calling this method.
1096 */
1097
1098 /**
1099 * Callback function used by the {@link CB_AudioFileSpritesPool#checkPlayingAll} method that will be called when not all was performed successfully.
1100 * @memberof CB_AudioFileSpritesPool
1101 * @callback CB_AudioFileSpritesPool.checkPlayingAll_CALLBACK_ERROR
1102 * @param {Object} errorsObject - Object whose property names are the ID of each sprites group or "GENERAL_ERROR" if the error is not related to any sprites group and their value will be a {@link CB_AudioFileSpritesPool.checkPlayingAll_CALLBACK_ERROR_OBJECT} object.
1103 * @param {integer} performedActions - The number of {@link CB_AudioFile} objects that can be played).
1104 * @param {integer|undefined} uncheckedObjects - The number of {@link CB_AudioFile} objects that needed to be checked before calling this method (it will be undefined if it could not be determined).
1105 */
1106
1107/**
1108 * An object with errors, used by the {@link CB_AudioFileSpritesPool.checkPlayingAll_CALLBACK_ERROR} callback (used by the {@link CB_AudioFileSpritesPool#checkPlayingAll} method).
1109 * @memberof CB_AudioFileSpritesPool
1110 * @typedef {Object} CB_AudioFileSpritesPool.checkPlayingAll_CALLBACK_ERROR_OBJECT
1111 * @property {string} error - A string describing the error (if it was possible to be determined).
1112 * @property {integer} checked - The number of {@link CB_AudioFile} objects that can be played.
1113 * @property {integer|undefined} needed - The number of {@link CB_AudioFile} objects that needed to be checked before calling this method (it will be undefined if it could not be determined).
1114 */
1115
1116/**
1117 * Checks whether each {@link CB_AudioFile} object whose {@link CB_AudioFile#getStatus} method returns the "unchecked" value (which belongs to the value of the {@link CB_AudioFile#UNCHECKED} property) can be played or not. After checking, if the audio can be played, the status of the {@link CB_AudioFile} object will get the value of {@link CB_AudioFile.LOADED}. Otherwise, if it cannot be played, the status of the {@link CB_AudioFile} object will get the value of {@link CB_AudioFile.FAILED}. If a {@link CB_AudioFile} object cannot be played and it is determined necessary, it will try to reload it internally (by calling the {@link CB_AudioFileCache#removeAudioFile} method). It will call the {@link CB_AudioFileCache#clearAudioFiles} method internally after finishing each call to the {@link CB_AudioFileSprites#checkPlayingAll} method. Uses the {@link CB_AudioFileSprites#checkPlayingAll} method internally. Recommended to be called through a user-driven event (as onClick, onTouch, etc.).
1118 * @function
1119 * @param {CB_AudioFileSpritesPool.checkPlayingAll_CALLBACK_OK} [callbackOk] - A function which will be called if all the {@link CB_AudioFile} objects whose {@link CB_AudioFile#getStatus} method returned the "unchecked" value (which belongs to the value of the {@link CB_AudioFile#UNCHECKED} property) could finally be checked successfully and all can be played, being "this" the {@link CB_AudioFileSpritesPool} object itself.
1120 * @param {CB_AudioFileSpritesPool.checkPlayingAll_CALLBACK_ERROR} [callbackError] - A function which will be called if not all the {@link CB_AudioFile} objects whose {@link CB_AudioFile#getStatus} method returned the "unchecked" value (which belongs to the value of the {@link CB_AudioFile#UNCHECKED} property) could finally be checked successfully and any cannot be played, being "this" the {@link CB_AudioFileSpritesPool} object itself. This function will be called immediately if the method was previously called and it is still running currently.
1121 * @param {boolean} [ignoreQueue=false] - Used as the "ignoreQueue" parameter when calling the {@link CB_AudioFileSprites#checkPlayingAll} method internally.
1122 * @param {boolean} [ignoreStatus=false] - If it is set to false and the sprites pool object is loaded (the {@link CB_AudioFileSpritesPool#getStatus} method returns the value set in the {@link CB_AudioFileSpritesPool.LOADED} property), it will exit returning an error. Otherwise, if it is set to true, it will ignore the current sprites pool object status.
1123 * @returns {integer} Returns the number of {@link CB_AudioFile} objects whose status belonged to the "unchecked" value (the value of the {@link CB_AudioFile#UNCHECKED} property) before the execution of this method. It will return 0 (zero) if the method is tried to be executed while there is another previous call of it still running. It will also return 0 (zero) if the status of audio sprites pool is neither loaded (the {@link CB_AudioFileSpritesPool#getStatus} method does not returns the value set in the {@link CB_AudioFileSpritesPool.LOADED} property) nor unchecked (the {@link CB_AudioFileSpritesPool#status} method does not return the value set in the {@link CB_AudioFileSpritesPool.UNCHECKED} property).
1124 */
1125CB_AudioFileSpritesPool.prototype.checkPlayingAll = function(callbackOk, callbackError, ignoreQueue, ignoreStatus)
1126{
1127 var errorMessage = "";
1128 if (this._checkPlayingAllPerforming)
1129 {
1130 errorMessage = "Method checkPlayingAll is being processed. Cannot be called again until it finishes.";
1131 }
1132 else if (!ignoreStatus &amp;&amp; this.getStatus() !== CB_AudioFileSpritesPool.LOADED &amp;&amp; this.getStatus() !== CB_AudioFileSpritesPool.UNCHECKED)
1133 {
1134 errorMessage = "Sprites pool is not loaded.";
1135 }
1136
1137 if (errorMessage !== "")
1138 {
1139 if (typeof(callbackError) === "function")
1140 {
1141 callbackError.call
1142 (
1143 this,
1144 {
1145 "GENERAL_ERROR" :
1146 {
1147 "error" : errorMessage,
1148 "checked" : 0
1149 }
1150 },
1151 0,
1152 undefined
1153 );
1154 }
1155 return 0;
1156 }
1157
1158 this._checkPlayingAllPerforming = true;
1159
1160 clearInterval(this._checkPlayingAllInterval);
1161
1162 var uncheckedObjects = 0;
1163 var failed = 0;
1164 var succeeded = 0;
1165 var needed = 0;
1166 var objectsChecked = 0;
1167 var errorsChecking = {};
1168 for (var spritesGroupId in this.audioFileSprites)
1169 {
1170 uncheckedObjects +=
1171 this.audioFileSprites[spritesGroupId].checkPlayingAll
1172 (
1173 function(performedActions) //callbackOk:
1174 {
1175 objectsChecked += performedActions;
1176 succeeded++;
1177 },
1178 function(error, performedActions, needed) //callbackError:
1179 {
1180 objectsChecked += performedActions;
1181 failed++;
1182 errorsChecking[spritesGroupId] = {};
1183 errorsChecking[spritesGroupId].error = error;
1184 errorsChecking[spritesGroupId].checked = performedActions;
1185 errorsChecking[spritesGroupId].needed = needed;
1186 },
1187 ignoreQueue //ignoreQueue.
1188 );
1189 needed++;
1190 }
1191
1192 var that = this;
1193 this._checkPlayingAllInterval =
1194 setInterval
1195 (
1196 function()
1197 {
1198 if (succeeded >= needed)
1199 {
1200 if (typeof(callbackOk) === "function") { callbackOk.call(that, objectsChecked, uncheckedObjects); }
1201 clearInterval(that._checkPlayingAllInterval);
1202 that._checkPlayingAllPerforming = false;
1203 }
1204 else if (succeeded + failed >= needed)
1205 {
1206 if (typeof(callbackError) === "function") { callbackError.call(that, errorsChecking, objectsChecked, uncheckedObjects); }
1207 clearInterval(that._checkPlayingAllInterval);
1208 that._checkPlayingAllPerforming = false;
1209 }
1210 }
1211 , 100);
1212
1213 return uncheckedObjects;
1214}
1215
1216
1217/**
1218 * Tries to play all the {@link CB_AudioFile} objects by calling their {@link CB_AudioFile#play} method internally. If a {@link CB_AudioFile} object cannot be played and it is determined necessary, it will try to reload it internally (by calling the {@link CB_AudioFileCache#removeAudioFile} method). Uses the {@link CB_AudioFileSprites#playAll} method internally.
1219 * @function
1220 * @param {number} [startAt=0 | {@link CB_AudioFile_API.WAAPI#lastStartAt} | {@link CB_AudioFile_API.SM2#lastStartAt} | {@link CB_AudioFile_API.ACMP#lastStartAt} | {@link CB_AudioFile_API.AAPI#lastStartAt} | stopAt] - Used as the "startAt" parameter when calling the {@link CB_AudioFileSprites#playAll} method internally.
1221 * @param {number} [stopAt={@link CB_AudioFile_API.WAAPI#getDuration}() | {@link CB_AudioFile_API.SM2#getDuration}() | {@link CB_AudioFile_API.ACMP#getDuration}() | {@link CB_AudioFile_API.AAPI#getDuration}()] - Used as the "stopAt" parameter when calling the {@link CB_AudioFileSprites#playAll} method internally.
1222 * @param {boolean} [loop={@link CB_AudioFile#loop}] - Used as the "loop" parameter when calling the {@link CB_AudioFileSprites#playAll} method internally.
1223 * @param {number} [volume=CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_DEFAULT ? CB_Speaker.getVolume() : CB_Configuration.CrossBase.CB_Speaker_DEFAULT_VOLUME] - Used as the "volume" parameter when calling the {@link CB_AudioFileSprites#playAll} method internally.
1224 * @param {boolean} [avoidDelayedPlay=false] - Used as the "avoidDelayedPlay" parameter when calling the {@link CB_AudioFileSprites#playAll} method internally.
1225 * @param {boolean} [allowedRecursiveDelay={@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_ALLOWED_RECURSIVE_DELAY_DEFAULT}] - Used as the "allowedRecursiveDelay" parameter when calling the {@link CB_AudioFileSprites#playAll} method internally.
1226 * @param {function} [onPlayStart] - Used as the "onPlayStart" parameter when calling the {@link CB_AudioFileSprites#playAll} method internally.
1227 * @param {function} [onStop] - Used as the "onStop" parameter when calling the {@link CB_AudioFileSprites#playAll} method internally.
1228 * @param {boolean} [includingPlaying=false] - Used as the "includingPlaying" parameter when calling the {@link CB_AudioFileSprites#playAll} method internally.
1229 * @returns {integer} Returns the number of {@link CB_AudioFile} objects whose {@link CB_AudioFile#play} method did not return the value of "-1" (this does not mean necessarily that they could be played successfully).
1230 */
1231CB_AudioFileSpritesPool.prototype.playAll = function(startAt, stopAt, loop, volume, avoidDelayedPlay, allowedRecursiveDelay, onPlayStart, onStop, includingPlaying)
1232{
1233 var played = 0;
1234 for (var spritesGroupId in this.audioFileSprites)
1235 {
1236 played += this.audioFileSprites[spritesGroupId].playAll(startAt, stopAt, loop, volume, avoidDelayedPlay, allowedRecursiveDelay, onPlayStart, onStop, includingPlaying);
1237 }
1238 return played;
1239}
1240
1241
1242/**
1243 * Tries to stops all the existing {@link CB_AudioFile} objects or the desired ones (if provided), which are being played, by calling their {@link CB_AudioFile#stop} method internally. Uses the {@link CB_AudioFileSprites#stopAll} method internally.
1244 * @function
1245 * @param {array} [audioFiles={@link CB_AudioFileCache#audioFiles}] - Used as the "audioFiles" parameter when calling the {@link CB_AudioFileSprites#stopAll} method internally.
1246 * @returns {integer} Returns the number of calls to the {@link CB_AudioFile#stop} method that were performed.
1247 */
1248CB_AudioFileSpritesPool.prototype.stopAll = function(audioFiles)
1249{
1250 var performed = 0;
1251 for (var spritesGroupId in this.audioFileSprites)
1252 {
1253 performed += this.audioFileSprites[spritesGroupId].stopAll(audioFiles);
1254 }
1255 return performed;
1256}
1257
1258
1259/**
1260 * Plays silently and stops all {@link CB_AudioFile} objects after a desired time. It can be useful for some clients which need the {@link CB_AudioFile#play} method to be called through a user-driven event (as onClick, onTouch, etc.). Internally, it calls {@link CB_AudioFileCache#playAll}(0, null, false, 0, true, null, null, null, includingPlaying) and, after a desired delay, calls the {@link CB_AudioFileCache#stopAll} method. Uses the {@link CB_AudioFileSprites#playAndStopAll} method internally.
1261 * @function
1262 * @param {boolean} [includingPlaying=false] - Used as the "includingPlaying" parameter when calling the {@link CB_AudioFileSprites#playAndStopAll} method internally.
1263 * @param {number} [delayBeforeStop=100] - Used as the "delayBeforeStop" parameter when calling the {@link CB_AudioFileSprites#playAndStopAll} method internally.
1264 * @returns {integer} Returns the number of {@link CB_AudioFile} objects whose {@link CB_AudioFile#play} method did not return the value of "-1" (this does not mean necessarily that they could be played successfully).
1265 */
1266CB_AudioFileSpritesPool.prototype.playAndStopAll = function(includingPlaying, delayBeforeStop)
1267{
1268 var played = 0;
1269 for (var spritesGroupId in this.audioFileSprites)
1270 {
1271 played += this.audioFileSprites[spritesGroupId].playAndStopAll(includingPlaying, delayBeforeStop);
1272 }
1273 return played;
1274}
1275
1276
1277/**
1278 * Tries to pause all the existing {@link CB_AudioFile} objects or the desired ones (if provided), which are being played, by calling their {@link CB_AudioFile#pause} method internally. Uses the {@link CB_AudioFileSprites#pauseAll} method internally.
1279 * @function
1280 * @param {function} [onPause] - Used as the "onPause" parameter when calling the {@link CB_AudioFileSprites#pauseAll} method internally.
1281 * @param {array} [audioFiles={@link CB_AudioFileCache#audioFiles}] - Used as the "audioFiles" parameter when calling the {@link CB_AudioFileSprites#pauseAll} method internally.
1282 * @returns {integer} Returns the number of calls to the {@link CB_AudioFile#pause} method that were performed.
1283 */
1284CB_AudioFileSpritesPool.prototype.pauseAll = function(onPause, audioFiles)
1285{
1286 var performed = 0;
1287 for (var spritesGroupId in this.audioFileSprites)
1288 {
1289 performed += this.audioFileSprites[spritesGroupId].pauseAll(onPause, audioFiles);
1290 }
1291 return performed;
1292}
1293
1294
1295/**
1296 * Resumes all the existing {@link CB_AudioFile} objects or the desired ones (if provided), which are paused (and not stopped). Can be focused on just one sprite ID if desired. Uses the {@link CB_AudioFileSprites#resumeAll} method internally. Internal usage only recommended. To resume a sprite, better use the {@link CB_AudioFileSprites#resumeSprite} method instead.
1297 * @function
1298 * @param {boolean} [loop={@link CB_AudioFile#loop}] - Used as the "loop" parameter when calling the {@link CB_AudioFileSprites#resumeAll} method internally.
1299 * @param {boolean} [allowedRecursiveDelay={@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_ALLOWED_RECURSIVE_DELAY_DEFAULT}] - Used as the "allowedRecursiveDelay" parameter when calling the {@link CB_AudioFileSprites#resumeAll} method internally.
1300 * @param {boolean} [allowedRecursiveDelaySkipping=stopAt-startAt] - Used as the "allowedRecursiveDelaySkipping" parameter when calling the {@link CB_AudioFileSprites#resumeAll} method internally.
1301 * @param {function} [onPlayStart] - Used as the "onPlayStart" parameter when calling the {@link CB_AudioFileSprites#resumeAll} method internally.
1302 * @param {function} [onStop] - Used as the "onStop" parameter when calling the {@link CB_AudioFileSprites#resumeAll} method internally.
1303 * @param {array} [audioFiles={@link CB_AudioFileCache#audioFiles}] - Used as the "audioFiles" parameter when calling the {@link CB_AudioFileSprites#resumeAll} method internally.
1304 * @param {string} [spriteId='_WITHOUT_SPRITE_ASSOCIATED'] - Used as the "spriteId" when calling the {@link CB_AudioFileSprites#resumeAll} method internally. Internal usage only recommended.
1305 * @returns {Object} Returns an object whose property names will be the ID of each sprites group and their value will be the returning value of the internal call to the {@link CB_AudioFileSprites#resumeAll} method.
1306 */
1307CB_AudioFileSpritesPool.prototype.resumeAll = function(loop, allowedRecursiveDelay, allowedRecursiveDelaySkipping, onPlayStart, onStop, audioFiles, spriteId)
1308{
1309 var soundInstances = {};
1310 for (var spritesGroupId in this.audioFileSprites)
1311 {
1312 soundInstances[spritesGroupId] = this.audioFileSprites[spritesGroupId].resumeAll(loop, allowedRecursiveDelay, allowedRecursiveDelaySkipping, onPlayStart, onStop, audioFiles, spriteId);
1313 }
1314 return soundInstances;
1315}
1316
1317
1318/**
1319 * Mutes all the existing {@link CB_AudioFile} objects or the desired ones (if provided). Uses the {@link CB_AudioFileSprites#muteAll} method internally.
1320 * @function
1321 * @param {function} [onMute] - Used as the "onMute" parameter when calling the {@link CB_AudioFileSprites#muteAll} method internally.
1322 * @param {array} [audioFiles={@link CB_AudioFileCache#audioFiles}] - Used as the "audioFiles" parameter when calling the {@link CB_AudioFileSprites#muteAll} method internally.
1323 * @returns {integer} Returns the number of calls to the {@link CB_AudioFile#mute} method that were performed.
1324 */
1325CB_AudioFileSpritesPool.prototype.muteAll = function(onMute, audioFiles)
1326{
1327 var performed = 0;
1328 for (var spritesGroupId in this.audioFileSprites)
1329 {
1330 performed += this.audioFileSprites[spritesGroupId].muteAll(onMute, audioFiles);
1331 }
1332 return performed;
1333}
1334
1335
1336/**
1337 * Unmutes all the existing {@link CB_AudioFile} objects or the desired ones (if provided). Uses the {@link CB_AudioFileSprites#unmuteAll} method internally.
1338 * @function
1339 * @param {function} [onUnmute] - Used as the "onUnmute" parameter when calling the {@link CB_AudioFileSprites#unmuteAll} method internally.
1340 * @param {array} [audioFiles={@link CB_AudioFileCache#audioFiles}] - Used as the "audioFiles" parameter when calling the {@link CB_AudioFileSprites#unmuteAll} method internally.
1341 * @returns {integer} Returns the number of calls to the {@link CB_AudioFile#unmute} method that were performed.
1342 */
1343CB_AudioFileSpritesPool.prototype.unmuteAll = function(onUnmute, audioFiles)
1344{
1345 var performed = 0;
1346 for (var spritesGroupId in this.audioFileSprites)
1347 {
1348 performed += this.audioFileSprites[spritesGroupId].unmuteAll(onUnmute, audioFiles);
1349 }
1350 return performed;
1351}
1352
1353
1354/**
1355 * Sets the same volume for all the existing {@link CB_AudioFile} objects or the desired ones (if provided). Uses the {@link CB_AudioFileSprites#setVolumeAll} method internally.
1356 * @function
1357 * @param {number} [volume={@link CB_Speaker.getVolume()} | {@link CB_Configuration.CrossBase.CB_Speaker_DEFAULT_VOLUME}] - Used as the "volume" parameter when calling the {@link CB_AudioFileSprites#setVolumeAll} method internally.
1358 * @param {boolean} [forceSetVolumeProperty=false] - Used as the "forceSetVolumeProperty" parameter when calling the {@link CB_AudioFileSprites#setVolumeAll} method internally.
1359 * @param {function} [onSetVolume] - Used as the "onSetVolume" parameter when calling the {@link CB_AudioFileSprites#setVolumeAll} method internally.
1360 * @param {array} [audioFiles={@link CB_AudioFileCache#audioFiles}] - Used as the "audioFiles" parameter when calling the {@link CB_AudioFileSprites#setVolumeAll} method internally.
1361 * @returns {integer} Returns the number of calls to the {@link CB_AudioFile#setVolume} method that were performed internally.
1362 */
1363CB_AudioFileSpritesPool.prototype.setVolumeAll = function(volume, forceSetVolumeProperty, onSetVolume, audioFiles)
1364{
1365 var performed = 0;
1366 for (var spritesGroupId in this.audioFileSprites)
1367 {
1368 performed += this.audioFileSprites[spritesGroupId].setVolumeAll(volume, forceSetVolumeProperty, onSetVolume, audioFiles);
1369 }
1370 return performed;
1371}
1372
1373
1374/**
1375 * Callback function used by the {@link CB_AudioFileSpritesPool#setAudioAPIAll} method that will be called when all the process was performed successfully.
1376 * @memberof CB_AudioFileSpritesPool
1377 * @callback CB_AudioFileSpritesPool.setAudioAPIAll_CALLBACK_OK
1378 * @param {integer} objectsChangedAPI - The number of {@link CB_AudioFile} objects that actually changed its audio API.
1379 * @param {integer} performedActions - The number of {@link CB_AudioFile} objects that ended with a desired audio API, including those ones which were already using it.
1380 * @param {integer} actionsNeeded - The total number of {@link CB_AudioFile} objects that were considered to perform the action (it will be undefined if it could not be determined).
1381 */
1382
1383 /**
1384 * Callback function used by the {@link CB_AudioFileCache#setAudioAPIAll} method that will be called when any error happened.
1385 * @memberof CB_AudioFileSpritesPool
1386 * @callback CB_AudioFileSpritesPool.setAudioAPIAll_CALLBACK_ERROR
1387 * @param {Object} errorsObject - Object whose property names are the ID of each sprites group or "GENERAL_ERROR" if the error is not related to any sprites group and their value will be a {@link CB_AudioFileSpritesPool.setAudioAPIAll_CALLBACK_ERROR_OBJECT} object each.
1388 * @param {integer} errorsHappened - The number of errors that happened, which could be greater than 1 if more than one internal call to the {@link CB_AudioFile#setAudioAPI} method failed.
1389 * @param {integer} objectsChangedAPI - The number of {@link CB_AudioFile} objects that actually changed its audio API.
1390 * @param {integer} performedActions - The number of {@link CB_AudioFile} objects that ended with a desired audio API, including those ones which were already using it.
1391 * @param {integer|undefined} actionsNeeded - The total number of {@link CB_AudioFile} objects that were considered to perform the action (it will be undefined if it could not be determined).
1392 */
1393
1394 /**
1395 * Object used by the {@link CB_AudioFileSpritesPool.setAudioAPIAll_CALLBACK_ERROR} callback. Unless it belongs to a general error, its information will only be regarding a certain sprites group.
1396 * @memberof CB_AudioFileSpritesPool
1397 * @typedef {Object} CB_AudioFileSpritesPool.setAudioAPIAll_CALLBACK_ERROR_OBJECT
1398 * @property {string} error - A string describing the error, if it was possible to be determined.
1399 * @property {integer} errors - The number of errors that happened, which could be greater than 1 if more than one internal call to the {@link CB_AudioFile#setAudioAPI} method failed.
1400 * @property {integer} changed - The number of objects that actually changed its audio API.
1401 * @property {integer} performed - The number of {@link CB_AudioFile} objects that ended with a desired audio API, including those ones which were already using it.
1402 * @property {integer|undefined} needed - The total number of {@link CB_AudioFile} objects that were considered to perform the action (it will be undefined if it could not be determined).
1403 */
1404
1405/**
1406 * Tries to change the audio API for all the existing {@link CB_AudioFile} objects or the desired ones (if provided). This method is not allowed to be called if a previous call to it did not finish yet. The function defined in the "callbackError" parameter, if any, will be called immediately if the method was previously called and it is still running currently. Uses the {@link CB_AudioFileSprites#setAudioAPIAll} method internally.
1407 * @function
1408 * @param {array|string} preferredAPIs - Used as the "preferredAPIs" parameter when calling the {@link CB_AudioFileSprites#setAudioAPIAll} method internally.
1409 * @param {CB_AudioFileSpritesPool.setAudioAPIAll_CALLBACK_OK} [callbackOk] - Function that will be called when all the process was performed successfully, being "this" the {@link CB_AudioFileSpritesPool} object.
1410 * @param {CB_AudioFileSpritesPool.setAudioAPIAll_CALLBACK_ERROR} [callbackError] - Function that will be called when any error happened, being "this" the {@link CB_AudioFileSpritesPool} object. This function will be called immediately if the method was previously called and it is still running currently.
1411 * @param {boolean} [mandatory=false] - Used as the "mandatory" parameter when calling the {@link CB_AudioFileSprites#setAudioAPIAll} method internally.
1412 * @param {string} [forceReload=false] - Used as the "forceReload" parameter when calling the {@link CB_AudioFileSprites#setAudioAPIAll} method internally.
1413 * @param {array} [audioFiles={@link CB_AudioFileCache#audioFiles}] - Used as the "audioFiles" parameter when calling the {@link CB_AudioFileSprites#setAudioAPIAll} method internally.
1414 * @returns {integer} Returns the number of calls to the {@link CB_AudioFile#setAudioAPI} method that were performed.
1415 */
1416CB_AudioFileSpritesPool.prototype.setAudioAPIAll = function(preferredAPIs, callbackOk, callbackError, mandatory, forceReload, audioFiles, ignoreStatus)
1417{
1418 var errorMessage = "";
1419 if (this._setAudioAPIAllPerforming)
1420 {
1421 errorMessage = "Method setAudioAPIAll is being processed. Cannot be called again until it finishes.";
1422 }
1423 else if (!ignoreStatus &amp;&amp; this.getStatus() !== CB_AudioFileSpritesPool.LOADED)
1424 {
1425 errorMessage = "Sprites pool is not loaded.";
1426 }
1427
1428 if (errorMessage !== "")
1429 {
1430 if (typeof(callbackError) === "function")
1431 {
1432 callbackError.call
1433 (
1434 this,
1435 {
1436 "GENERAL_ERROR" :
1437 {
1438 "error" : errorMessage,
1439 "errors" : 1,
1440 "changed" : 0,
1441 "performed" : 0,
1442 "needed" : undefined
1443 }
1444 },
1445 1,
1446 0,
1447 0,
1448 undefined
1449 );
1450 }
1451 return 0;
1452 }
1453
1454 this._setAudioAPIAllPerforming = true;
1455
1456 clearInterval(this._setAudioAPIAllInterval);
1457
1458 var performedReturn = 0;
1459 var failed = 0;
1460 var succeeded = 0;
1461 var needed = 0;
1462 var objectsChanged = 0;
1463 var errorsChecking = {};
1464 var errors = 0;
1465 var performed = 0;
1466 var neededTotal = 0;
1467 for (var spritesGroupId in this.audioFileSprites)
1468 {
1469 performedReturn +=
1470 this.audioFileSprites[spritesGroupId].setAudioAPIAll
1471 (
1472 preferredAPIs, //preferredAPIs.
1473 function(objectsChangedAPI, performedActions, actionsNeeded) //callbackOk:
1474 {
1475 objectsChanged += objectsChangedAPI;
1476 performed += performedActions;
1477 actionsNeeded = parseInt(actionsNeeded); //It could be undefined.
1478 neededTotal += actionsNeeded;
1479 succeeded++;
1480 },
1481 function(error, errorsHappened, objectsChangedAPI, performedActions, actionsNeeded) //callbackError:
1482 {
1483 failed++;
1484
1485 actionsNeeded = parseInt(actionsNeeded); //It could be undefined.
1486
1487 errors += errorsHappened;
1488 objectsChanged += objectsChangedAPI;
1489 performed += performedActions;
1490 neededTotal += actionsNeeded;
1491
1492 errorsChecking[spritesGroupId] = {};
1493 errorsChecking[spritesGroupId].error = error;
1494 errorsChecking[spritesGroupId].errors = errorsHappened;
1495 errorsChecking[spritesGroupId].changed = objectsChangedAPI;
1496 errorsChecking[spritesGroupId].performed = performedActions;
1497 errorsChecking[spritesGroupId].needed = actionsNeeded;
1498 },
1499 mandatory, //mandatory.
1500 forceReload, //forceReload.
1501 audioFiles //audioFiles
1502 );
1503 needed++;
1504 }
1505
1506 var that = this;
1507 this._setAudioAPIAllInterval =
1508 setInterval
1509 (
1510 function()
1511 {
1512 if (succeeded >= needed)
1513 {
1514 if (typeof(callbackOk) === "function") { callbackOk.call(that, objectsChanged, performed, neededTotal); }
1515 clearInterval(that._setAudioAPIAllInterval);
1516 that._setAudioAPIAllPerforming = false;
1517 }
1518 else if (succeeded + failed >= needed)
1519 {
1520 if (typeof(callbackError) === "function") { callbackError.call(that, errorsChecking, errors, objectsChanged, performed, neededTotal); }
1521 clearInterval(that._setAudioAPIAllInterval);
1522 that._setAudioAPIAllPerforming = false;
1523 }
1524 }
1525 , 100);
1526
1527 return performedReturn;
1528}
1529
1530
1531/**
1532 * Tells whether any of the {@link CB_AudioFile} objects is playing or not. Uses the {@link CB_AudioFileSprites#isPlaying} method internally.
1533 * @function
1534 * @returns {boolean} Returns whether any of the {@link CB_AudioFile} objects is playing or not.
1535 */
1536CB_AudioFileSpritesPool.prototype.isPlaying = function()
1537{
1538 for (var spritesGroupId in this.audioFileSprites)
1539 {
1540 if (this.audioFileSprites[spritesGroupId].isPlaying()) { return true; }
1541 }
1542 return false;
1543}
1544
1545
1546/**
1547 * Tells the current number of free {@link CB_AudioFile} objects (the number of objects which are available and ready to use). Uses the {@link CB_AudioFileSprites#getAudioFilesFreeNumber} method internally.
1548 * @function
1549 * @returns {integer} Returns the current number of free {@link CB_AudioFile} objects (the number of objects which are available and ready to use).
1550 */
1551CB_AudioFileSpritesPool.prototype.getAudioFilesFreeNumber = function()
1552{
1553 var number = 0;
1554 for (var spritesGroupId in this.audioFileSprites)
1555 {
1556 number += this.audioFileSprites[spritesGroupId].getAudioFilesFreeNumber();
1557 }
1558 return number;
1559}
1560
1561
1562/**
1563 * Gets an object with arrays or a one-dimension array with all the {@link CB_AudioFile} objects. Uses the {@link CB_AudioFileSprites#getAudioFiles} method internally.
1564 * @function
1565 * @param {boolean} [copy=false] - Used as the "copy" parameter when calling the {@link CB_AudioFileSprites#getAudioFiles} method internally.
1566 * @param {boolean} [oneDimension=false] - If it is set to true, the method will return an array with all the {@link CB_AudioFile} objects. Otherwise, if it is set to false, the method will return an object whose property names will be the ID of each sprites group and their value will be an array with all the {@link CB_AudioFile} objects that belong to that sprites group.
1567 * @returns {Object|array} If the "oneDimension" parameter is set to true, returns an array with all the {@link CB_AudioFile} objects. Otherwise, if the "oneDimension" parameter is set to false, it will return an object whose property names will be the ID of each sprites group and their value will be an array with all the {@link CB_AudioFile} objects that belong to that sprites group.
1568 */
1569CB_AudioFileSpritesPool.prototype.getAudioFiles = function(copy, oneDimension)
1570{
1571 var audioFiles;
1572 if (!oneDimension)
1573 {
1574 audioFiles = {};
1575 for (var spritesGroupId in this.audioFileSprites)
1576 {
1577 audioFiles[spritesGroupId] = this.audioFileSprites[spritesGroupId].getAudioFiles(copy);
1578 }
1579 }
1580 else
1581 {
1582 audioFiles = [];
1583 var audioFilesSpritesGroup;
1584 var audioFilesSpritesGroupLength;
1585 var y = 0;
1586 var x = 0;
1587 for (var spritesGroupId in this.audioFileSprites)
1588 {
1589 audioFilesSpritesGroup = this.audioFileSprites[spritesGroupId].getAudioFiles(copy);
1590 audioFilesSpritesGroupLength = audioFilesSpritesGroup.length;
1591 for (x = 0; x &lt; audioFilesSpritesGroupLength; x++)
1592 {
1593 audioFiles[y++] = audioFilesSpritesGroup[x];
1594 }
1595 }
1596 }
1597 return audioFiles;
1598}
1599
1600
1601/**
1602 * Gets an object with arrays or a one-dimension array with the free {@link CB_AudioFile} objects (the objects which are available and ready to use). Uses the {@link CB_AudioFileSprites#getAudioFilesFree} method internally.
1603 * @function
1604 * @param {boolean} [oneDimension=false] - If it is set to true, the method will return an array with the free {@link CB_AudioFile} objects. Otherwise, if it is set to false, the method will return an object whose property names will be the ID of each sprites group and their value will be an array with the free {@link CB_AudioFile} objects that belong to that sprites group.
1605 * @returns {Object|array} If the "oneDimension" parameter is set to true, returns an array with the free {@link CB_AudioFile} objects. Otherwise, if the "oneDimension" parameter is set to false, it will return an object whose property names will be the ID of each sprites group and their value will be an array with the free {@link CB_AudioFile} objects that belong to that sprites group.
1606 */
1607CB_AudioFileSpritesPool.prototype.getAudioFilesFree = function(oneDimension)
1608{
1609 var audioFiles;
1610 if (!oneDimension)
1611 {
1612 audioFiles = {};
1613 for (var spritesGroupId in this.audioFileSprites)
1614 {
1615 audioFiles[spritesGroupId] = this.audioFileSprites[spritesGroupId].getAudioFilesFree();
1616 }
1617 }
1618 else
1619 {
1620 audioFiles = [];
1621 var audioFilesSpritesGroup;
1622 var audioFilesSpritesGroupLength;
1623 var y = 0;
1624 var x = 0;
1625 for (var spritesGroupId in this.audioFileSprites)
1626 {
1627 audioFilesSpritesGroup = this.audioFileSprites[spritesGroupId].getAudioFilesFree();
1628 audioFilesSpritesGroupLength = audioFilesSpritesGroup.length;
1629 for (x = 0; x &lt; audioFilesSpritesGroupLength; x++)
1630 {
1631 audioFiles[y++] = audioFilesSpritesGroup[x];
1632 }
1633 }
1634 }
1635 return audioFiles;
1636}
1637
1638
1639/**
1640 * Gets an object with arrays or a one-dimension array with the busy {@link CB_AudioFile} objects (the objects which are not available and ready to use). Uses the {@link CB_AudioFileSprites#getAudioFilesBusy} method internally.
1641 * @function
1642 * @param {boolean} [oneDimension=false] - If it is set to true, the method will return an array with the busy {@link CB_AudioFile} objects. Otherwise, if it is set to false, the method will return an object whose property names will be the ID of each sprites group and their value will be an array with the busy {@link CB_AudioFile} objects that belong to that sprites group.
1643 * @returns {Object|array} If the "oneDimension" parameter is set to true, returns an array with the busy {@link CB_AudioFile} objects. Otherwise, if the "oneDimension" parameter is set to false, it will return an object whose property names will be the ID of each sprites group and their value will be an array with the busy {@link CB_AudioFile} objects that belong to that sprites group.
1644 */
1645CB_AudioFileSpritesPool.prototype.getAudioFilesBusy = function(oneDimension)
1646{
1647 var audioFiles;
1648 if (!oneDimension)
1649 {
1650 audioFiles = {};
1651 for (var spritesGroupId in this.audioFileSprites)
1652 {
1653 audioFiles[spritesGroupId] = this.audioFileSprites[spritesGroupId].getAudioFilesBusy();
1654 }
1655 }
1656 else
1657 {
1658 audioFiles = [];
1659 var audioFilesSpritesGroup;
1660 var audioFilesSpritesGroupLength;
1661 var y = 0;
1662 var x = 0;
1663 for (var spritesGroupId in this.audioFileSprites)
1664 {
1665 audioFilesSpritesGroup = this.audioFileSprites[spritesGroupId].getAudioFilesBusy();
1666 audioFilesSpritesGroupLength = audioFilesSpritesGroup.length;
1667 for (x = 0; x &lt; audioFilesSpritesGroupLength; x++)
1668 {
1669 audioFiles[y++] = audioFilesSpritesGroup[x];
1670 }
1671 }
1672 }
1673 return audioFiles;
1674}
1675
1676
1677/**
1678 * Tells the number of {@link CB_AudioFile} objects created. Uses the {@link CB_AudioFileSprites#getAudioFilesNumber} method internally.
1679 * @function
1680 * @param {boolean} [real=false] - Used as the "real" parameter when calling the {@link CB_AudioFileSprites#getAudioFilesNumber} method internally.
1681 * @returns {integer} Returns the number of {@link CB_AudioFile} objects created.
1682 */
1683CB_AudioFileSpritesPool.prototype.getAudioFilesNumber = function(real)
1684{
1685 var number = 0;
1686 for (var spritesGroupId in this.audioFileSprites)
1687 {
1688 number += this.audioFileSprites[spritesGroupId].getAudioFilesNumber(real);
1689 }
1690 return number;
1691}
1692
1693
1694/**
1695 * Returns a number representing the percentage of the loading progress for the audio sprites pool object (from 0 to 100, being 100 a complete loading progress). The way to calculate it internally may differ from one audio API to another and it is not totally reliable. Uses the {@link CB_AudioFileSprites#getProgress} method internally.
1696 * @function
1697 * @param {boolean} [countLoadedObjects=false] - Used as the "countLoadedObjects" parameter when calling the {@link CB_AudioFileSprites#getProgress} method internally.
1698 * @param {boolean} [alsoUncheckedAndCheckingObjects=false] - Used as the "alsoUncheckedAndCheckingObjects" parameter when calling the {@link CB_AudioFileSprites#getProgress} method internally.
1699 * @returns {number} Returns a number representing the percentage of the loading progress for the audio sprites pool object (from 0 to 100, being 100 a complete loading progress). The way to calculate it internally may differ from one audio API to another and it is not totally reliable.
1700 */
1701CB_AudioFileSpritesPool.prototype.getProgress = function(countLoadedObjects, alsoUncheckedAndCheckingObjects)
1702{
1703 var progress = 0;
1704 var spritesGroups = 0;
1705 for (var spritesGroupId in this.audioFileSprites)
1706 {
1707 progress += this.audioFileSprites[spritesGroupId].getProgress(countLoadedObjects, alsoUncheckedAndCheckingObjects);
1708 spritesGroups++;
1709 }
1710 if (spritesGroups !== 0) { progress /= spritesGroups; }
1711 return progress;
1712}
1713
1714
1715/**
1716 * Gets the current status of the audio file sprites pool object. Uses the {@link CB_AudioFileSprites#getStatus} method internally.
1717 * @function
1718 * @returns {number} Returns the current status of the audio file sprites pool object. It is a number, affected by the returning value of the {@link CB_AudioFileSprites#getStatus} method of each {@link CB_AudioFileSprites} object used internally, which should match the value of the {@link CB_AudioFileCache.UNLOADED} (still unloaded), {@link CB_AudioFileCache.LOADING} (loading), {@link CB_AudioFileCache.UNCHECKED} (not checked by calling the {@link CB_AudioFileCache#checkPlayingAll} method yet), {@link CB_AudioFileCache.CHECKING} (being checked by the {@link CB_AudioFileCache#checkPlayingAll} method), {@link CB_AudioFileCache.LOADED} (loaded), {@link CB_AudioFileCache.FAILED} (failed loading or failed to play or by any other reason) or {@link CB_AudioFileCache.ABORTED} (aborted because it was destroyed with the "destructor" method) property.
1719 */
1720CB_AudioFileSpritesPool.prototype.getStatus = function()
1721{
1722 var status = null;
1723
1724 var allLoaded = false;
1725 var loaded = 0;
1726
1727 var anyUnloaded = false;
1728 var anyLoading = false;
1729 var anyUnchecked = false;
1730 var anyChecking = false;
1731 var anyFailed = false;
1732 var anyAborted = false;
1733
1734 for (var audioFileSpritesObject in this.audioFileSprites)
1735 {
1736 if (this.audioFileSprites[audioFileSpritesObject].getStatus() === CB_AudioFileCache.UNLOADED) { anyUnloaded = true; }
1737 else if (this.audioFileSprites[audioFileSpritesObject].getStatus() === CB_AudioFileCache.LOADING) { anyLoading = true; }
1738 else if (this.audioFileSprites[audioFileSpritesObject].getStatus() === CB_AudioFileCache.UNCHECKED) { anyUnchecked = true; }
1739 else if (this.audioFileSprites[audioFileSpritesObject].getStatus() === CB_AudioFileCache.CHECKING) { anyChecking = true; }
1740 else if (this.audioFileSprites[audioFileSpritesObject].getStatus() === CB_AudioFileCache.FAILED) { anyFailed = true; }
1741 else if (this.audioFileSprites[audioFileSpritesObject].getStatus() === CB_AudioFileCache.ABORTED) { anyAborted = true; }
1742 else { loaded++; }
1743 }
1744
1745 if (anyUnloaded) { status = CB_AudioFileSpritesPool.UNLOADED; }
1746 else if (anyLoading) { status = CB_AudioFileSpritesPool.LOADING; }
1747 else if (anyUnchecked) { status = CB_AudioFileSpritesPool.UNCHECKED; }
1748 else if (anyChecking) { status = CB_AudioFileSpritesPool.CHECKING; }
1749 else if (anyFailed) { status = CB_AudioFileSpritesPool.FAILED; }
1750 else if (anyAborted) { status = CB_AudioFileSpritesPool.ABORTED; }
1751
1752 if (status === null)
1753 {
1754 if (loaded > 0) { status = CB_AudioFileSpritesPool.LOADED; }
1755 else if (this._aborted) { status = CB_AudioFileSpritesPool.ABORTED; }
1756 else { status = CB_AudioFileSpritesPool.UNLOADED; }
1757 }
1758
1759 return status;
1760}
1761
1762
1763/**
1764 * Gets the current status of the audio file sprites pool object, as a string.
1765 * @function
1766 * @returns {string} Returns the current status of the audio file sprites pool object, as a string. Possible return values are "UNLOADED", "LOADING", "UNCHECKED", "CHECKING", "LOADED", "FAILED", "ABORTED" or "UNKNOWN (UNKNOWN_STATUS)" (where "UNKNOWN_STATUS" will be a returning value from the {@link CB_AudioFileSpritesPool#getStatus} method not recognized as any possible status).
1767 */
1768CB_AudioFileSpritesPool.prototype.getStatusString = function()
1769{
1770 var status = this.getStatus();
1771 var statuses = [ "UNLOADED", "LOADING", "UNCHECKED", "CHECKING", "LOADED", "FAILED", "ABORTED" ];
1772 if (typeof(statuses[status]) !== "undefined") { return statuses[status]; }
1773 else { return "UNKNOWN (" + status + ")"; }
1774}
1775
1776
1777/**
1778 * Calls the error function which should be set in the {@link CB_AudioFileSprites#onError} property (if any), being "this" the {@link CB_AudioFileSpritesPool} object itself. Internal usage only recommended.
1779 * @function
1780 * @param {string} [message] - The message describing the error that will be sent to the set {@link CB_AudioFileSprites#onError} function (if any) as the first and unique parameter.
1781 * @param {boolean} [ignorePreviousExecution=false] - If it is set to false, the function set in the {@link CB_AudioFileSprites#onError} property (if any) will only be called if it was not executed previously.
1782 * @returns {boolean} Returns true if the {@link CB_AudioFileSprites#onError} function could be called or false otherwise.
1783 */
1784CB_AudioFileSpritesPool.prototype.errorFunction = function(message, ignorePreviousExecution)
1785{
1786 if (ignorePreviousExecution || !this._errorFunctionExecuted)
1787 {
1788 if (typeof(this.onError) === "function") { this._errorFunctionExecuted = true; this.onError.call(this, message); return true; }
1789 }
1790 return false;
1791}</pre>
1792 </article>
1793</section>
1794
1795
1796
1797
1798
1799 </div>
1800 </div>
1801
1802 <div class="clearfix"></div>
1803
1804
1805
1806</div>
1807</div>
1808
1809
1810 <div class="modal fade" id="searchResults">
1811 <div class="modal-dialog">
1812 <div class="modal-content">
1813 <div class="modal-header">
1814 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
1815 <h4 class="modal-title">Search results</h4>
1816 </div>
1817 <div class="modal-body"></div>
1818 <div class="modal-footer">
1819 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
1820 </div>
1821 </div><!-- /.modal-content -->
1822 </div><!-- /.modal-dialog -->
1823 </div>
1824
1825
1826<footer>
1827
1828
1829 <span class="copyright">
1830 <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>
1831 </span>
1832
1833<span class="jsdoc-message">
1834 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
1835
1836 on Mon Feb 3rd 2020
1837
1838 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
1839</span>
1840</footer>
1841
1842<script src="scripts/docstrap.lib.js"></script>
1843<script src="scripts/toc.js"></script>
1844
1845 <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
1846
1847
1848<script>
1849$( function () {
1850 $( "[id*='$']" ).each( function () {
1851 var $this = $( this );
1852
1853 $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
1854 } );
1855
1856 $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
1857 var $this = $( this );
1858
1859 var example = $this.find( "code" );
1860 exampleText = example.html();
1861 var lang = /{@lang (.*?)}/.exec( exampleText );
1862 if ( lang && lang[1] ) {
1863 exampleText = exampleText.replace( lang[0], "" );
1864 example.html( exampleText );
1865 lang = lang[1];
1866 } else {
1867 var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
1868 lang = langClassMatch ? langClassMatch[1] : "javascript";
1869 }
1870
1871 if ( lang ) {
1872
1873 $this
1874 .addClass( "sunlight-highlight-" + lang )
1875 .addClass( "linenums" )
1876 .html( example.html() );
1877
1878 }
1879 } );
1880
1881 Sunlight.highlightAll( {
1882 lineNumbers : true,
1883 showMenu : true,
1884 enableDoclinks : true
1885 } );
1886
1887 $.catchAnchorLinks( {
1888 navbarOffset: 10
1889 } );
1890 $( "#toc" ).toc( {
1891 anchorName : function ( i, heading, prefix ) {
1892 return $( heading ).attr( "id" ) || ( prefix + i );
1893 },
1894 selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
1895 showAndHide : false,
1896 smoothScrolling: true
1897 } );
1898
1899 $( "#main span[id^='toc']" ).addClass( "toc-shim" );
1900 $( '.dropdown-toggle' ).dropdown();
1901
1902 $( "table" ).each( function () {
1903 var $this = $( this );
1904 $this.addClass('table');
1905 } );
1906
1907} );
1908</script>
1909
1910
1911
1912<!--Navigation and Symbol Display-->
1913
1914<script>
1915 $( function () {
1916 $( '#main' ).localScroll( {
1917 offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
1918 } );
1919 $( "dt.name" ).each( function () {
1920 var $this = $( this ).find("h4");
1921 var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
1922 var dt = $(this);
1923 var children = dt.next( "dd" );
1924
1925 dt.prepend( icon ).css( {cursor : "pointer"} );
1926 dt.addClass( "member-collapsed" ).addClass( "member" );
1927
1928
1929 children.hide();
1930
1931 dt.children().on( "click", function () {
1932 children = dt.next( "dd" );
1933 children.slideToggle( "fast", function () {
1934
1935 if ( children.is( ":visible" ) ) {
1936 icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
1937 dt.addClass( "member-open" ).animate( "member-collapsed" );
1938 } else {
1939 icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
1940 dt.addClass( "member-collapsed" ).removeClass( "member-open" );
1941 }
1942 } );
1943 } );
1944
1945 } );
1946 } );
1947</script>
1948
1949
1950<!--Google Analytics-->
1951
1952
1953
1954 <script type="text/javascript">
1955 $(document).ready(function() {
1956 SearcherDisplay.init();
1957 });
1958 </script>
1959
1960
1961</body>
1962</html>