UNPKG

103 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_AudioFile.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_AudioFile.js</h1>
83
84<section>
85 <article>
86 <pre
87 class="sunlight-highlight-javascript linenums">/**
88 * @file Audio files management, including abstraction for different audio APIs. 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}). Contains the {@link CB_AudioFile} 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 * The constructor is recommended to be called through a user-driven event (as onClick, onTouch, etc.) if the "autoPlay" option is set to true, as some clients may need this at least the first time in order to be able to play the audio.
96 * @class
97 * @classdesc Class to manage an audio file. Internally, it uses one audio API object which belongs to the audio API being used (when the audio API is changed, it keeps the old audio API objects just in case they are needed in the future when the audio API is changed again). Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
98 * @param {string} filePath - The path of the audio file or a data URI. NOTE: Only some clients with some audio APIs will support data URIs.
99 * @param {string} [audioId='CB_AudioFile_' + CB_AudioFile._idUnique++] - Desired identifier for the audio object (can be a different element depending on the audio API used). If not provided, an automatic unique ID will be calculated. Note that it is not case sensitive and it should be unique for each object.
100 * @param {CB_AudioFile.OPTIONS} [options={@link CB_AudioFile#DEFAULT_OPTIONS}] - Object with the desired options.
101 * @param {string} [audioAPI=CB_AudioDetector.getPreferredAPI(undefined, false, null) || CB_AudioDetector.getPreferredAPI(undefined, true, null)] - The desired audio API to be used. If not provided, it will try to calculate the best one for the current client by calling the {@link CB_AudioDetector.getPreferredAPI} function internally. Audio API support will depend on the current client being used. All possible ones are defined in {@link CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS}. For example: "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
102 * @param {function} [callbackOk] - Function with no parameters to be called when the audio has been loaded successfully, being "this" the {@link CB_AudioFile} object itself.
103 * @param {function} [callbackError] - Function to be called if the audio has not been loaded successfully. The first and unique parameter will be a string describing the error found (if it could be determined), being "this" the {@link CB_AudioFile} object itself.
104 * @returns {CB_AudioFile} Returns a new {@link CB_AudioFile} object.
105 * @todo Do not allow to create one object with an "id" which has already been used (unless the value is undefined, null...). Note that the "id" is not case sensitive and it should be unique for each object.
106 * @todo Send the {@link CB_AudioFile} object itself as a parameter when calling both "callbackOk" and "callbackError".
107 * @todo Think about allowing to define 'useXHR' and 'useCache' options (used by {@link CB_AudioFile_API.WAAPI} objects).
108 * @todo Method getCopy and static method filterProperties (similar to the ones from {@link CB_GraphicSprites} and {@link CB_GraphicSpritesScene}).
109 */
110var CB_AudioFile = function(filePath, audioId, options, audioAPI, callbackOk, callbackError)
111{
112 //Creates an instance of this object and returns it in the case that it is being called from an unexpected context:
113 if (this === window || !(this instanceof CB_AudioFile)) { return new CB_AudioFile(filePath, audioId, options, audioAPI, callbackOk, callbackError); }
114
115 //Constants:
116 /**
117 * Keeps the default volume. If the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_DEFAULT} property is true, this will keep the result of calling the {@link CB_Speaker.getVolume} function. Otherwise, it will use the value of the {@link CB_Configuration.CrossBase.CB_Speaker_DEFAULT_VOLUME} variable.
118 * @constant
119 * @type {number}
120 * @default CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_DEFAULT ? CB_Speaker.getVolume() : CB_Configuration.CrossBase.CB_Speaker_DEFAULT_VOLUME
121 */
122 CB_AudioFile.prototype.DEFAULT_VOLUME = CB_Configuration[CB_BASE_NAME].CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_DEFAULT ? CB_Speaker.getVolume() : CB_Configuration[CB_BASE_NAME].CB_Speaker_DEFAULT_VOLUME;
123
124 /**
125 * Keeps the default options when an object is created. Format: { autoLoad: boolean, autoPlay: boolean, loop: boolean, volume: number }.
126 * @constant
127 * @type {CB_AudioFile.OPTIONS}
128 * @default { autoLoad: true, autoPlay: false, loop: false, volume: [CB_AudioFile.prototype.DEFAULT_VOLUME]{@link CB_AudioFile#DEFAULT_VOLUME} }
129 */
130 CB_AudioFile.prototype.DEFAULT_OPTIONS = { autoLoad: true, autoPlay: false, loop: false, volume: CB_AudioFile.prototype.DEFAULT_VOLUME };
131
132
133 //Properties and variables:
134 /**
135 * Defines whether the file loops by default when the audio is played or not. Its value will be modified automatically whenever the {@link CB_AudioFile#play} method is called, getting the value from the "loop" parameter (but only if contains a boolean).
136 * @var
137 * @readonly
138 * @type {boolean}
139 * @default [CB_AudioFile.prototype.DEFAULT_OPTIONS]{@link CB_AudioFile#DEFAULT_OPTIONS}.loop
140 */
141 this.loop = CB_AudioFile.prototype.DEFAULT_OPTIONS.loop;
142
143 /**
144 * Stores the volume of this audio. Accepted values go from 0 to MAX_VOLUME, where MAX_VOLUME is 100 if the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM} property is false or otherwise MAX_VOLUME is the returning value of the {@link CB_Speaker.getVolume} function.
145 * @var
146 * @readonly
147 * @type {number}
148 * @default [CB_AudioFile.prototype.DEFAULT_OPTIONS]{@link CB_AudioFile#DEFAULT_OPTIONS}.volume
149 */
150 this.volume = CB_AudioFile.prototype.DEFAULT_OPTIONS.volume;
151
152 /**
153 * Stores the identifier for the audio file.
154 * @var
155 * @readonly
156 * @type {string}
157 * @default 'CB_AudioFile_' + CB_AudioFile._idUnique++
158 */
159 this.id = "";
160
161 /**
162 * Stores the path of the audio file or the data URI. NOTE: Only some clients with some audio APIs will support data URIs.
163 * @var
164 * @readonly
165 * @type {string}
166 * @default
167 */
168 this.filePath = "";
169
170 /**
171 * Defines the Audio API used for this audio file. Audio API support will depend on the current client being used. All possible ones are defined in {@link CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS}. For example: "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
172 * @var
173 * @readonly
174 * @type {string}
175 * @default
176 */
177 this.audioAPI = null;
178
179 this._onStopFunction = null; //Function to call when the audio stops.
180
181
182 //Fake AudioFile[x] object:
183 var that = this;
184 CB_AudioFile._audioFileObject_prototype = CB_AudioFile._audioFileObject_prototype ||
185 {
186 usingPrototype : true,
187 status : CB_AudioFile.UNLOADED,
188 paused : false,
189 stopped : true,
190 destructor : function() {},
191 getDuration : function() { return 0; },
192 checkPlaying :
193 function(callbackOk, callbackError)
194 {
195 if (typeof(callbackError) === "function") { callbackError.call(that, "audioFileObject is not loaded (using CB_AudioFile._audioFileObject_prototype)"); }
196 return false;
197 },
198 play : function() {},
199 resume : function() {},
200 pause : function() {},
201 stop : function() {},
202 volume : this.DEFAULT_OPTIONS.volume,
203 volumeBeforeMute : this.DEFAULT_OPTIONS.volume,
204 setVolume :
205 function(volume)
206 {
207 var MAX_VOLUME = CB_Configuration[CB_BASE_NAME].CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM ? CB_Speaker.getVolume() : 100;
208 if (volume > MAX_VOLUME) { volume = MAX_VOLUME; }
209 else if (volume &lt; 0) { volume = 0; }
210 this.volume = volume;
211 return volume;
212 },
213 mute :
214 function()
215 {
216 this.volumeBeforeMute = this.volume;
217 this.volume = 0;
218 return 0;
219 },
220 unmute :
221 function()
222 {
223 this.volume = this.volumeBeforeMute;
224 return this.volume;
225 },
226 getCurrentTime : function() { return 0; },
227 onStop : function() { return false; },
228 getProgress : function() { return 0; }
229 };
230 CB_AudioFile._audioFileObject_prototype.volume = CB_AudioFile.prototype.DEFAULT_OPTIONS.volume; //Updates the property because maybe the volume has changed.
231 CB_AudioFile._audioFileObject_prototype.volumeBeforeMute = CB_AudioFile.prototype.DEFAULT_OPTIONS.volume; //Updates the property because maybe the volume has changed.
232
233 /**
234 * It will store the created audio file objects for the different audio APIs (for optimization purposes, to avoid creating more than one per API). Being each index the name of the audio API ("WAAPI", "AAPI", "SM2" or "ACMP"), their value will be an object which can be {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}). Recommended for internal usage only.
235 * @var
236 * @type {Object}
237 * @default
238 */
239 this.audioFileObjects = {}; //It will store the created objects for the different audio APIs (for optimization purposes, to avoid creating more than one per API).
240
241
242 /**
243 * It will store the current audio file object for the current audio API. The {@link CB_AudioFile#load} method will set the value of this property only after the audio file object (stored in its value) is loaded properly. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}). When no audio API object is being set, it will contain a fake object with same methods and properties (defined in {@link CB_AudioFile._audioFileObject_prototype}). Recommended for internal usage only.
244 * @var
245 * @type {CB_AudioFile_API.WAAPI | CB_AudioFile_API.SM2 | CB_AudioFile_API.ACMP | CB_AudioFile_API.AAPI | Object}
246 * @default
247 */
248 this.audioFileObject = CB_AudioFile._audioFileObject_prototype;
249
250 /**
251 * Stores the last audio file object created or reused, for the current API being used. The {@link CB_AudioFile#load} method will set the value of this property before knowing whether the audio file object (stored in its value) will be loaded properly or not. Used by the {@link CB_AudioFile#load} and {@link CB_AudioFile#getProgress} methods. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}). When no audio API object is being set, it will contain a fake object with same methods and properties (defined in {@link CB_AudioFile._audioFileObject_prototype}). Recommended for internal usage only.
252 * @var
253 * @type {CB_AudioFile_API.WAAPI | CB_AudioFile_API.SM2 | CB_AudioFile_API.ACMP | CB_AudioFile_API.AAPI | Object}
254 * @default
255 */
256 this.audioFileObjectLast = CB_AudioFile._audioFileObject_prototype;
257
258 this._loadingAudioFileObject = false; //Tells when the audio object is being loading.
259
260 //Variables to keep same parameters when API is changed:
261 this._avoidDelayedPlayLast = null;
262 this._allowedRecursiveDelayLast = null;
263 //this._onPlayStartLast = undefined;
264 this._onLoadErrorLast = null;
265
266
267 //Calls the constructor of the object when creates an instance:
268 return this._init(filePath, audioId, options, audioAPI, callbackOk, callbackError);
269}
270
271
272/**
273 * Object with the options for an audio file. The format is the following one: { autoLoad: boolean, autoPlay: boolean, loop: boolean, volume: number }.
274 * @memberof CB_AudioFile
275 * @typedef {Object} CB_AudioFile.OPTIONS
276 * @property {boolean} [autoLoad={@link CB_AudioFile#DEFAULT_OPTIONS}.autoLoad] - Value which will be used as the "autoLoad" parameter when calling the {@link CB_AudioFile#setAudioAPI} method internally (when the constructor is called).
277 * @property {boolean} [autoPlay={@link CB_AudioFile#DEFAULT_OPTIONS}.autoPlay] - Value which will be used as the "autoPlay" parameter when calling the {@link CB_AudioFile#setAudioAPI} method internally (when the constructor is called).
278 * @property {boolean} [loop={@link CB_AudioFile#DEFAULT_OPTIONS}.loop] - Value that will be used for the {@link CB_AudioFile#loop} property.
279 * @property {number} [volume={@link CB_AudioFile#DEFAULT_OPTIONS}.volume] - The desired volume (from 0 to the maximum value, where the maximum value will be the returning value of calling the {@link CB_Speaker.getVolume} function if the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM} property is set to true or it will be 100 otherwise) that will be used for the {@link CB_AudioFile#volume} property.
280 */
281
282
283//Static properties and constants:
284CB_AudioFile._idUnique = 0; //Counter to make the id unique.
285
286/**
287 * Status value for an audio file which is unloaded. Can be used to compare the value returned by the {@link CB_AudioFile#getStatus} method. Recommended for internal usage only.
288 * @constant
289 * @type {integer}
290 * @default 0
291 */
292CB_AudioFile.UNLOADED = 0;
293
294/**
295 * Status value for an audio file which is loading. Can be used to compare the value returned by the {@link CB_AudioFile#getStatus} method. Recommended for internal usage only.
296 * @constant
297 * @type {integer}
298 * @default
299 */
300CB_AudioFile.LOADING = 1;
301
302/**
303 * Status value for an audio file which has been not checked yet. Can be used to compare the value returned by the {@link CB_AudioFile#getStatus} method. Recommended for internal usage only.
304 * @constant
305 * @type {integer}
306 * @default
307 */
308CB_AudioFile.UNCHECKED = 2;
309
310/**
311 * Status value for an audio file which is being checked currently. Can be used to compare the value returned by the {@link CB_AudioFile#getStatus} method. Recommended for internal usage only.
312 * @constant
313 * @type {integer}
314 * @default
315 */
316CB_AudioFile.CHECKING = 3;
317
318/**
319 * Status value for an audio file which has been loaded. Can be used to compare the value returned by the {@link CB_AudioFile#getStatus} method. Recommended for internal usage only.
320 * @constant
321 * @type {integer}
322 * @default
323 */
324CB_AudioFile.LOADED = 4;
325
326/**
327 * Status value for an audio file which failed to be loaded or failed for any other reason. Can be used to compare the value returned by the {@link CB_AudioFile#getStatus} method. Recommended for internal usage only.
328 * @constant
329 * @type {integer}
330 * @default
331 */
332CB_AudioFile.FAILED = 5;
333
334/**
335 * Status value for an audio file which has been aborted. This will happen when the audio file has been destroyed with the {@link CB_AudioFile#destructor} method. Can be used to compare the value returned by the {@link CB_AudioFile#getStatus} method. Recommended for internal usage only.
336 * @constant
337 * @type {integer}
338 * @default
339 */
340CB_AudioFile.ABORTED = 6;
341
342
343//Constructor:
344CB_AudioFile.prototype._init = function(filePath, audioId, options, audioAPI, callbackOk, callbackError)
345{
346 //If not given, defines the default parameters:
347 if (typeof(audioId) === "undefined" || audioId === null) { audioId = "CB_AudioFile_" + CB_AudioFile._idUnique++; } //Uses the file path as default id.
348 if (typeof(options) === "undefined" || options === null) { options = this.DEFAULT_OPTIONS; }
349 else
350 {
351 if (typeof(options.loop) === "undefined" || options.loop === null) { options.loop = this.DEFAULT_OPTIONS.loop; }
352 if (typeof(options.autoLoad) === "undefined" || options.autoLoad === null) { options.autoLoad = this.DEFAULT_OPTIONS.autoLoad; }
353 if (typeof(options.autoPlay) === "undefined" || options.autoPlay === null) { options.autoPlay = this.DEFAULT_OPTIONS.autoPlay; }
354 if (typeof(options.volume) === "undefined" || options.volume === null) { options.volume = this.DEFAULT_OPTIONS.volume; }
355 }
356
357 //Sets the audio ID:
358 this.id = CB_trim(audioId).toUpperCase();
359
360 //Sets the file path:
361 this.filePath = filePath;
362
363 //Sets whether it will loop or not:
364 this.loop = options.loop;
365
366 //Sets the volume:
367 //this.volume = options.volume;
368 this.setVolume(options.volume);
369
370 //Sets the audio API and proceeds according to the options received:
371 this.setAudioAPI(audioAPI, options.autoLoad, options.autoPlay, callbackOk, callbackError); //Will load the audio too.
372
373 //Returns the object:
374 return this;
375}
376
377
378/**
379 * Destroys the audio file object and frees memory. Sets its current status to ABORTED ({@link CB_AudioFile.ABORTED} value).
380 * @function
381 * @param {boolean} [stopSound=false] - If set to true, it will also call the "stop" method of the internal audio file object for the current API (stored in the {@link CB_AudioFile#audioFileObject} property). This method has the same parameters as the {@link CB_AudioFile#stop} method.
382 * @param {boolean} [keepStoppedUnaltered=false] - Used internally as the "keepStoppedUnaltered" parameter to call the "stop" method of the internal audio file object for the current API (stored in the {@link CB_AudioFile#audioFileObject} property). This method has the same parameters as the {@link CB_AudioFile#stop} method. If the "stopSound" parameter is not set to true, this parameter will be ignored as the "stop" method will not be called.
383 * @param {boolean} [avoidOnStop=false] - Used internally as the "avoidOnStop" parameter to call the "stop" method of the internal audio file object for the current API (stored in the {@link CB_AudioFile#audioFileObject} property). This method has the same parameters as the {@link CB_AudioFile#stop} method. If the "stopSound" parameter is not set to true, this parameter will be ignored as the "stop" method will not be called.
384 * @param {boolean} [forceOnStop=false] - Used internally as the "forceOnStop" parameter to call the "stop" method of the internal audio file object for the current API (stored in the {@link CB_AudioFile#audioFileObject} property). This method has the same parameters as the {@link CB_AudioFile#stop} method. If the "stopSound" parameter is not set to true, this parameter will be ignored as the "stop" method will not be called.
385 */
386CB_AudioFile.prototype.destructor = function(stopSound, keepStoppedUnaltered, avoidOnStop, forceOnStop)
387{
388 this.audioFileObject.destructor(stopSound, keepStoppedUnaltered, avoidOnStop, forceOnStop);
389 this.audioFileObject = CB_AudioFile._audioFileObject_prototype;
390 this.audioFileObject.status = CB_AudioFile.ABORTED;
391}
392
393
394/**
395 * Sets the desired audio API. This method will also be called automatically by the constructor. If the "autoLoad" parameter is set to true, it will call the {@link CB_AudioFile#load} method internally, changing the audio API on-the-fly, and the audio will try to continue playing if it was playing at the moment of calling this method. Check the {@link CB_AudioFile#load} method documentation for more information. If the "autoLoad" parameter is set to true, it 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. The audio API used will be stored in the {@link CB_AudioFile#audioAPI} property.
396 * @function
397 * @param {string} [audioAPI=CB_AudioDetector.getPreferredAPI(undefined, false, null) || CB_AudioDetector.getPreferredAPI(undefined, true, null)] - The desired audio API to be used. If not provided, it will try to calculate the best one for the current client by calling the {@link CB_AudioDetector.getPreferredAPI} function internally. Audio API support will depend on the current client being used. All possible ones are defined in {@link CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS}. For example: "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}). Used internally as the "audioAPI" parameter when calling the {@link CB_AudioFile#load} method internally (only when the "autoLoad" parameter is set to true).
398 * @param {string} [autoLoad=true] - If set to false, it will not call the {@link CB_AudioFile#load} method internally and will only set the {@link CB_AudioFile#audioAPI} property (not recommended).
399 * @param {string} [autoPlay=false] - Used internally as the "autoPlay" parameter when calling the {@link CB_AudioFile#load} method internally (only when the "autoLoad" parameter is set to true).
400 * @param {function} [callbackOk] - Function with no parameters to be called when the audio has been loaded successfully, being "this" the {@link CB_AudioFile} object itself. Used internally as the "callbackOk" parameter when calling the {@link CB_AudioFile#load} method internally (only when the "autoLoad" parameter is set to true).
401 * @param {function} [callbackError] - Function to be called if the audio has not been loaded successfully. The first and unique parameter will be a string describing the error found (if it could be determined), being "this" the {@link CB_AudioFile} object itself. Used internally as the "callbackError" parameter when calling the {@link CB_AudioFile#load} method internally (only when the "autoLoad" parameter is set to true).
402 * @param {string} [ignoreOldValues=false] - Used internally as the "ignoreOldValues" parameter when calling the {@link CB_AudioFile#load} method internally (only when the "autoLoad" parameter is set to true).
403 * @param {string} [filePath={@link CB_AudioFile#filePath}] - Used internally as the "filePath" parameter when calling the {@link CB_AudioFile#load} method internally (only when the "autoLoad" parameter is set to true).
404 * @param {string} [forceReload=false] - Used internally as the "forceReload" parameter when calling the {@link CB_AudioFile#load} method internally (only when the "autoLoad" parameter is set to true).
405 * @returns {string} Returns the desired audio API that has been tried to set, in upper case (successfully or not).
406 * @todo Think about using the "forceReload" just after the "callbackError" to match the parameter order of the "load" method of all the audio API objects.
407 */
408 CB_AudioFile.prototype.setAudioAPI = function(audioAPI, autoLoad, autoPlay, callbackOk, callbackError, ignoreOldValues, filePath, forceReload)
409{
410 if (typeof(audioAPI) === "undefined" || audioAPI === null) //Uses the preferred API as default.
411 {
412 audioAPI = CB_AudioDetector.getPreferredAPI(undefined, false, null) || CB_AudioDetector.getPreferredAPI(undefined, true, null);
413 }
414
415 audioAPI = CB_trim(audioAPI).toUpperCase();
416
417 if (!CB_AudioDetector.APIExists(audioAPI))
418 {
419 if (typeof(callbackError) === "function") { callbackError.call(this, "Audio API given does not exist (" + audioAPI + ")."); }
420 return audioAPI;
421 }
422
423 if (typeof(autoLoad) === "undefined" || autoLoad === null) { autoLoad = true; }
424
425 //Since AJAX doesn't allow to load local files, if the file is local we can't use WAAPI:
426 //if (CB_isFileLocal(this.filePath)) { if (audioAPI === "WAAPI") { audioAPI = "SM2"; } } //Uses SM2 instead.
427
428 //If it is the same audio API as the current one, we don't need to do more:
429 if (this.audioAPI === audioAPI) { if (typeof(callbackOk) === "function") { callbackOk.call(this); } return audioAPI; }
430
431 //First time is undefined, so we accept any first value:
432 if (typeof(this.audioAPI) === "undefined") { this.audioAPI = audioAPI; }
433
434 //We (re)load the audio file if we want to (NOTE: audioAPI will change only if the object is created and loaded successfully):
435 if (autoLoad)
436 {
437 this.load(filePath ? filePath : this.filePath, audioAPI, autoPlay, callbackOk, callbackError, ignoreOldValues, forceReload);
438 }
439 //...otherwise, we just change the audioAPI property:
440 else { this.audioAPI = audioAPI; }
441
442 return audioAPI;
443}
444
445
446/**
447 * Loads the desired audio file with the desired options. 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. This method will be called automatically if the "autoLoad" option was set to true when calling the {@link CB_AudioFile#setAudioAPI} method. The audio API used will be stored in the {@link CB_AudioFile#audioAPI} property.
448 * When this method is called, if the "status" property of the audio API object already has the "LOADED" status (defined in the {@link CB_AudioFile.LOADED} constant) and the "forceReload" parameter is not set to true, it will exit calling the given "callbackOk" function (if any) immediately. Otherwise, regardless the status, the status will be set to "LOADING" (defined in the {@link CB_AudioFile.LOADING} constant). After it, it will reach the "UNCHECKED" (defined in the {@link CB_AudioFile.UNCHECKED} constant). If the "autoPlay" parameter is not set to true, this will be the final status (and it will be necessary to call the "checkPlaying" method of the audio API object after it). After it and only if the "autoPlay" is set to true, as the "checkPlaying" method of the audio API object will be called internally, it will have the "CHECKING" status (defined in the {@link CB_AudioFile.CHECKING} constant) and finally the "LOADED" status (defined in the {@link CB_AudioFile.LOADED} constant) if all goes well.
449 * Although it is not recommended to do so, if this method is called when the audio API object has the "UNCHECKED" status (defined in the {@link CB_AudioFile.UNCHECKED} constant), it will call the "checkPlaying" method of the audio API object internally.
450 * Internally, it can use the {@link CB_AudioFile#audioFileObjects} property as a cache.
451 * @function
452 * @param {string} [filePath={@link CB_AudioFile#filePath}] - The path of the audio file or a data URI. NOTE: Only some clients with some audio APIs will support data URIs.
453 * @param {string} [audioAPI={@link CB_AudioFile#audioAPI}] - The desired audio API to be used. If not provided, it will try to use the previously-set one (in the {@link CB_AudioFile#audioAPI} property). All possible ones are defined in {@link CB_Configuration.CrossBase.CB_AudioFileCache_PREFERRED_AUDIO_APIS}. For example: "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
454 * @param {string} [autoPlay=false] - If set to true, it will start playing the audio automatically (by calling the {@link CB_AudioFile#play} method internally) unless the "ignoreOldValues" parameter is set to false and the previous audio was playing or paused. If set to true and the "status" property of the audio API object reaches to the "UNCHECKED" status (defined in the {@link CB_AudioFile.UNCHECKED} constant), it will also call internally the "checkPlaying" method of the audio API object before anything. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
455 * @param {function} [callbackOk] - Function with no parameters to be called when the audio has been loaded successfully, being "this" the {@link CB_AudioFile} object itself.
456 * @param {function} [callbackError] - Function to be called if the audio has not been loaded successfully. The first and unique parameter will be a string describing the error found (if it could be determined), being "this" the {@link CB_AudioFile} object itself.
457 * @param {string} [ignoreOldValues=false] - If set to true, it will ignore the old values of the previous used audio API object. This means that it will neither continue playing if it was playing (changing the audio API on-the-fly) nor keep the paused status if it was paused nor copy its "loop" property to the new audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
458 * @param {string} [forceReload=false] - Used internally as the "forceReload" parameter when calling the "load" method of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
459 * @returns {CB_AudioFile_API.WAAPI|CB_AudioFile_API.SM2|CB_AudioFile_API.ACMP|CB_AudioFile_API.AAPI|null} Returns the used audio API object or null otherwise. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
460 * @todo Think about using the "forceReload" just after the "callbackError" to match the parameter order of the "load" method of all the audio API objects.
461 */
462CB_AudioFile.prototype.load = function(filePath, audioAPI, autoPlay, callbackOk, callbackError, ignoreOldValues, forceReload)
463{
464 //Defines the default parameters:
465 if (typeof(audioAPI) === "undefined" || audioAPI === null)
466 {
467 audioAPI = this.audioAPI; //Uses the previously set Audio API as default.
468 //if (typeof(audioAPI) === "undefined" || audioAPI === null) { audioAPI = CB_AudioDetector.getPreferredAPI(undefined, false, null) || CB_AudioDetector.getPreferredAPI(undefined, true, null); } //Uses the preferred API as default.
469 }
470
471 audioAPI = CB_trim(audioAPI).toUpperCase();
472
473 filePath = filePath || this.filePath;
474
475 var that = this;
476
477 var callbackErrorFunction =
478 function(error)
479 {
480 that._loadingAudioFileObject = false; //The audio object is not being loaded anymore.
481
482 that.audioFileObjectLast = that.audioFileObject;
483
484 //If we are using the prototype (no real audio object adopted), and the audio API requested has been set or the audio API was never set (first time), status is failed:
485 if (that.audioFileObject.usingPrototype &amp;&amp; (audioAPI === that.audioAPI || that.audioAPI === null)) //This way, we avoid setting as FAILED if the audio API has not been changed.
486 {
487 that.audioFileObject.status = CB_AudioFile.FAILED;
488 }
489
490 //Calls the error function (if any):
491 if (typeof(callbackError) === "function") { callbackError.call(that, error); }
492 };
493
494 //Creates the audio object depending on the API chosen:
495 if (typeof(CB_AudioFile_API) !== "undefined" &amp;&amp; typeof(CB_AudioFile_API[audioAPI]) !== "undefined")
496 {
497 this._loadingAudioFileObject = true; //The audio object is being loaded.
498 var callbackOkFunction =
499 function()
500 {
501 //If there is an object already:
502 var wasPlaying = false;
503 var wasPaused = false;
504
505 //If we wanto to play automatically and the status of the new object is unchecked, checks the file and the function will be called when finishes:
506 if (autoPlay &amp;&amp; audioFileObject.status === CB_AudioFile.UNCHECKED &amp;&amp; typeof(audioFileObject.checkPlaying) !== "undefined")
507 {
508 audioFileObject.checkPlaying(callbackOkFunction, callbackErrorFunction, false, false, false);
509 return;
510 }
511
512 //If we do not want to ignore old values and the previous audio file object used was not a prototype (it was a real one):
513 if (!ignoreOldValues &amp;&amp; typeof(that.audioFileObject.usingPrototype) === "undefined")
514 {
515 //If the status of the new object is unchecked, checks the file and the function will be called when finishes:
516 if (audioFileObject.status === CB_AudioFile.UNCHECKED &amp;&amp; typeof(audioFileObject.checkPlaying) !== "undefined")
517 {
518 audioFileObject.checkPlaying(callbackOkFunction, callbackErrorFunction, false, false, false);
519 return;
520 }
521
522 //var status = that.getStatus();
523 var status = that.audioFileObject.status;
524
525 //audioFileObject.status = LOADED;
526 //If the audio was LOADED:
527 if (status === CB_AudioFile.LOADED)
528 {
529 //Stores the startAt:
530 audioFileObject.lastStartAt = that.audioFileObject.lastStartAt;
531
532 //Stores the stopAt:
533 audioFileObject.lastStopAt = that.audioFileObject.lastStopAt;
534
535 //Stores loop:
536 that.loop = audioFileObject.loop = that.audioFileObject.loop;
537
538 //If the sound is playing, pauses it:
539 if (that.isPlaying())
540 {
541 //Stops it:
542 that.pause();
543 wasPlaying = true;
544 }
545 else if (that.audioFileObject.paused)
546 {
547 wasPaused = true;
548 }
549
550 //Stores the pause time (if any):
551 audioFileObject.pauseTime = that.audioFileObject.pauseTime;
552
553 //If it was using WAAPI and not now, we need to substract the startTime:
554 /*
555 if (that.audioAPI === "WAAPI" &amp;&amp; audioAPI !== "WAAPI" &amp;&amp; typeof(that.audioFileObject.startTime) !== "undefined" &amp;&amp; that.audioFileObject.startTime !== null &amp;&amp; !isNaN(that.audioFileObject.startTime))
556 {
557 audioFileObject.pauseTime -= that.audioFileObject.startTime * 1000;
558 }
559 */
560 }
561 }
562
563
564 //If we changed the API (this means the object will have changed too):
565 if (that.audioAPI !== audioAPI)
566 {
567 //Stops and destroys previous object (if any) and declares it as ABORTED:
568 //////that.destructor(true, false, true); //Stops the object (avoiding to fire onStop) and destroys the object (sets status as ABORTED).
569 }
570
571 //Stores the volume:
572 that.volume = audioFileObject.volume = that.getVolume();
573
574 //Stores the new audio object:
575 that.audioFileObject = audioFileObject;
576
577 //If it was playing, continues playing from the same point:
578 if (!ignoreOldValues &amp;&amp; (wasPlaying || wasPaused))
579 {
580 that.audioFileObject.stopped = false;
581 that.audioFileObject.paused = true;
582
583 //that.resume(that.loop);
584 //that.resume(that.loop, that._avoidDelayedPlayLast, that._allowedRecursiveDelayLast, that._onPlayStartLast, that._onLoadErrorLast);
585 that.resume(that.loop, that._avoidDelayedPlayLast, that._allowedRecursiveDelayLast, null, that._onLoadErrorLast);
586
587 if (wasPaused) { that.pause(); }
588 }
589 //...otherwise, if we wanted to play automatically, we start playing:
590 else if (autoPlay)
591 {
592 that.play();
593 }
594
595 //Now the new API can be accepted:
596 that.audioAPI = audioAPI;
597
598 //Sets the file path:
599 that.filePath = filePath;
600
601 //Set the desired onStop event (if any):
602 /////////that.onStop(that.onStopFunction, false);
603 that.onStop(that._onStopFunction, false);
604
605 that._loadingAudioFileObject = false; //The audio object has been loaded already.
606
607 //Calls the OK function (if any):
608 if (typeof(callbackOk) === "function") { callbackOk.call(that); }
609 };
610
611 //Creates a new CB_AudioFile[x] object or uses the existing one (if available):
612 var audioFileObject;
613 if (typeof(this.audioFileObjects[audioAPI]) !== "undefined" &amp;&amp; this.audioFileObjects[audioAPI] !== null)
614 {
615 //Gets the existing object:
616 audioFileObject = this.audioFileObjects[audioAPI];
617
618 //Sets the desired options:
619 ////if (typeof(this.id) === "undefined" || this.id === null) { audioFileObject.id = filePath; } //Uses the file path as default id.
620 if (typeof(this.id) === "undefined" || this.id === null) { audioFileObject.id = CB_trim("CB_AudioFile_" + CB_AudioFile._idUnique++).toUpperCase(); } //Uses the file path as default id.
621 else { audioFileObject.id = this.id; }
622 audioFileObject.loop = this.loop;
623 //audioFileObject.setVolume(this.volume);
624 //audioFileObject.setVolume(0); //Sets volume to zero to prevent hearing the sound in some web clients when checkPlaying is called.
625 if (CB_Configuration[CB_BASE_NAME].CB_AudioFile_AudioFileCache_MUTE_ON_LOAD_AND_CHECKING) { audioFileObject.mute(); } //Sets volume to zero to prevent hearing the sound in some web clients when checkPlaying is called.
626
627 //Calls the load method of the object (load method also calls the destructor method):
628 audioFileObject.load(filePath, false, callbackOkFunction, callbackErrorFunction, forceReload);
629 }
630 else
631 {
632 //Creates the new object and stores it (sets volume to zero to prevent hearing the sound in some web clients when checkPlaying is called):
633 //audioFileObject = new CB_AudioFile_API[audioAPI](filePath, this.id, { autoLoad: true, autoPlay: autoPlay, loop: this.loop, volume: this.volume }, callbackOkFunction, callbackErrorFunction);
634 this.DEFAULT_VOLUME = CB_Configuration[CB_BASE_NAME].CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_DEFAULT ? CB_Speaker.getVolume() : CB_Configuration[CB_BASE_NAME].CB_Speaker_DEFAULT_VOLUME;
635 audioFileObject = new CB_AudioFile_API[audioAPI](filePath, this.id, { autoLoad: true, autoPlay: false, loop: this.loop, volume: CB_Configuration[CB_BASE_NAME].CB_AudioFile_AudioFileCache_MUTE_ON_LOAD_AND_CHECKING ? 0 : this.DEFAULT_VOLUME }, callbackOkFunction, callbackErrorFunction);
636 this.audioFileObjects[audioAPI] = audioFileObject;
637 }
638
639 this.audioFileObjectLast = this.audioFileObjects[audioAPI];
640
641 return audioFileObject;
642 }
643 else
644 {
645 callbackErrorFunction("CB_AudioFile_API['" + audioAPI + "'] not found");
646 return null;
647 }
648}
649
650
651
652/**
653 * Checks whether the audio can be played or not. 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. Also recommended to use before calling the {@link CB_AudioFile#play} method the first time. Internally, uses the "checkPlaying" method of the used audio API object. The checking action will only be performed if the value of the "status" property of the used audio API object belongs to the {@link CB_AudioFile.UNCHECKED} or to the {@link CB_AudioFile.CHECKING} value. After checking, if the audio can be played, the "status" property of the used audio API object will get the value of {@link CB_AudioFile.LOADED}. Otherwise, if it cannot be played, the "status" property of the used audio API object will get the value of {CB_AudioFile.FAILED}. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
654 * @function
655 * @param {function} [callbackOk] - Function with no parameters to be called when the audio has been checked successfully, being "this" the {@link CB_AudioFile} object itself.
656 * @param {function} [callbackError] - Function to be called if the audio has not been checked successfully. The first and unique parameter will be a string describing the error found (if it could be determined), being "this" the {@link CB_AudioFile} object itself.
657 * @param {boolean} [ignoreStatus=false] - If set to false and the audio status is neither "UNCHECKED" nor "CHECKING", it will fail calling the "callbackError" function (if any). If set to true, it will try to perform the checking action regardless the status of the audio.
658 * @param {boolean} [ignoreQueue=false] - If set to false and there is already the maximum number of audio files being checked (defined internally, depending on the audio API), the function will exit and it will call itself automatically again and again until the checking process can be performed (when its queue turn has been reached). This is done for performance purposes. Some audio APIs will ignore this parameter as they do not use checking queues.
659 * @param {boolean} [useCache=false] - If set to true (not recommended) and the same audio file was checked previously, it will not perform the checking process again and it will do the same as the previous call. Some audio APIs will ignore this parameter as they do not use cache.
660 * @returns {boolean} Returns false if the checking could not be performed and failed. If it returns true, it can mean either the checking has been processed successfully or it will fail in the future, so it is recommended to ignore the returning value and use the callback functions instead.
661 */
662CB_AudioFile.prototype.checkPlaying = function(callbackOk, callbackError, ignoreStatus, ignoreQueue, useCache)
663{
664 var that = this;
665 return this.audioFileObject.checkPlaying
666 (
667 function() { if (typeof(callbackOk) === "function") { callbackOk.call(that); } }, //callbackOk.
668 function(error) { if (typeof(callbackError) === "function") { callbackError.call(that, error); } }, //callbackError.
669 ignoreStatus,
670 ignoreQueue,
671 useCache
672 );
673}
674
675
676/**
677 * Tells the duration of the audio (in milliseconds). Note that some clients might not calculate the duration correctly and, in this case, a zero (0) value would be returned. Internally, uses the "getDuration" method of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
678 * @function
679 * @returns {number} Returns the duration of the audio (in milliseconds). Note that some clients might not calculate the duration correctly and, in this case, a zero (0) value would be returned.
680 */
681CB_AudioFile.prototype.getDuration = function()
682{
683 return this.audioFileObject.getDuration();
684}
685
686
687/**
688 * Plays the audio. Internally, uses the "play" method of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
689 * @function
690 * @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] - Time in milliseconds where we want the audio to start at. If not provided or it is not a valid number, it will use zero (0) as default which belongs to the beginning of the audio. If the value provided is greater than the "stopAt" provided, it will use the value set in the "lastStartAt" property of the used audio API object (which belongs to the "startAt" value the last time that the "play" method was called). If, even using the "lastStartAt" value is still greather than the "stopAt" provided, it will use the same value as the "stopAt" which means it will not play and will stop immediately. Used internally as the "startAt" parameter to call the "play" method of the audio API object.
691 * @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}()] - Time in milliseconds where we want the audio to stop at. If not provided or it is not a valid number, it will use the returning value of the "getDuration" method of the used audio API object (which should belong to the total duration of the audio, if it was calculated correctly). Used internally as the "stopAt" parameter to call the "play" method of the audio API object.
692 * @param {boolean} [loop={@link CB_AudioFile#loop}] - Sets whether we want to play the audio looping (starting again and again) or just play it once. Note that at the end of each loop the "onStop" function defined (through the {@link CB_AudioFile#onStop} method) will not be called. Used internally as the "loop" parameter to call the "play" method of the audio API object.
693 * @param {boolean} [avoidDelayedPlay=false] - If set to false (recommended) and the audio failed previously or was aborted (destroyed), it will try to load it correctly again automatically and play it after that if possible (this can take some time so the audio could start playing after a delay). Otherwise, if set to true and the audio failed or was aborted (destroyed), the audio will not play at all and the "stop" method of the used audio API object will be called immediately. Used internally as the "avoidDelayedPlay" parameter to call the "play" method of the audio API object.
694 * @param {boolean} [allowedRecursiveDelay={@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_ALLOWED_RECURSIVE_DELAY_DEFAULT}] - The maximum amount of time (in milliseconds) of delay that we accept before start playing the audio. If the amount of time is overcome, the audio will not play at all and the "stop" method of the used audio API object will be called immediately. Used only when the "avoidDelayedPlay" parameter is set to false and the audio needs to be loaded because it failed previously or was aborted (destroyed). Used internally as the "allowedRecursiveDelay" parameter to call the "play" method of the audio API object.
695 * @param {function} [onPlayStart] - Function to be called when the audio starts playing successfully. The function will be called with the following parameters (in order): "startAt", "stopAt", "startAtNextLoop", "loop", "avoidDelayedPlay", "allowedRecursiveDelay" and "startPlayingTime", being "this" the {@link CB_AudioFile} object. If the audio is looping, this will be called only once when the audio starts playing the first time and it will not be called next loops. Used internally as the "onPlayStart" parameter to call the "play" method of the audio API object.
696 * @param {function} [onLoadError] - Function to be called if the audio cannot be played successfully. The first and unique parameter will be a string describing the error found (if it could be determined), being "this" the {@link CB_AudioFile} object. Used internally as the "onLoadError" parameter to call the "play" method of the audio API object.
697 * @param {boolean} [isResume=false] - If set to true (not recommended) and it is a looping audio, the next loop will use the value of the "lastStartAt" property of the audio API object as the "startAt" parameter when it calls the "play" method again automatically (internally). Recommended for internal usage only. Used internally as the "isResume" parameter to call the "play" method of the audio API object.
698 * @returns {boolean|integer} Returns the returning value of the "play" method of the audio API object. It returns false if the duration is 0 ("startAt" and "stopAt" are the same number), returns "-1" if the audio cannot be played and an error is detected or returns true otherwise. Note that even when it returns true there can be a non-detectable error and maybe the audio is not played. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
699 */
700CB_AudioFile.prototype.play = function(startAt, stopAt, loop, avoidDelayedPlay, allowedRecursiveDelay, onPlayStart, onLoadError, isResume)
701{
702 if (typeof(loop) === "undefined" || loop === null) { loop = this.loop; } //If not set, uses the default (or last one used).
703 else { this.loop = loop; } //...otherwise, stores the new setting given.
704
705 //Backups the parameters given:
706 this._avoidDelayedPlayLast = avoidDelayedPlay;
707 this._allowedRecursiveDelayLast = allowedRecursiveDelay;
708 //this._onPlayStartLast = onPlayStart;
709 this._onLoadErrorLast = onLoadError;
710
711 var that = this;
712
713 //Plays the sound:
714 return this.audioFileObject.play
715 (
716 startAt,
717 stopAt,
718 loop,
719 avoidDelayedPlay,
720 allowedRecursiveDelay,
721 function(startAt, stopAt, startAtNextLoop, loop, avoidDelayedPlay, allowedRecursiveDelay, startPlayingTime)
722 {
723 if (typeof(onPlayStart) === "function") { onPlayStart.call(that, startAt, stopAt, startAtNextLoop, loop, avoidDelayedPlay, allowedRecursiveDelay, startPlayingTime); }
724 },
725 function (error) { if (typeof(onPlayStart) === "function") { onLoadError.call(that, error); } },
726 isResume,
727 false
728 );
729}
730
731
732/**
733 * Resumes the audio (after being paused), starting from the same point it was paused previously. Internally, uses the "resume" method of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
734 * @function
735 * @param {boolean} [loop={@link CB_AudioFile#loop}] - Sets whether we want to play the audio looping (starting again and again) or just play it once. Note that at the end of each loop the "onStop" function defined (through the {@link CB_AudioFile#onStop} method) will not be called. Used internally as the "loop" parameter to call the "resume" method of the audio API object.
736 * @param {boolean} [avoidDelayedPlay=false] - If set to false (recommended) and the audio failed previously or was aborted (destroyed), it will try to load it correctly again automatically and play it after that if possible (this can take some time so the audio could start playing after a delay). Otherwise, if set to true and the audio failed or was aborted (destroyed), the audio will not play at all and the "stop" method of the used audio API object will be called immediately. Used internally as the "avoidDelayedPlay" parameter to call the "resume" method of the audio API object.
737 * @param {boolean} [allowedRecursiveDelay={@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_ALLOWED_RECURSIVE_DELAY_DEFAULT}] - The maximum amount of time (in milliseconds) of delay that we accept before start playing the audio. If the amount of time is overcome, the audio will not play at all and the "stop" method of the used audio API object will be called immediately. Used only when the "avoidDelayedPlay" parameter is set to false and the audio needs to be loaded because it failed previously or was aborted (destroyed). Used internally as the "allowedRecursiveDelay" parameter to call the "resume" method of the audio API object.
738 * @param {function} [onPlayStart] - Function to be called when the audio starts playing successfully. The function will be called with the following parameters (in order): "startAt", "stopAt", "startAtNextLoop", "loop", "avoidDelayedPlay", "allowedRecursiveDelay" and "startPlayingTime", being "this" the {@link CB_AudioFile} object. If the audio is looping, this will be called only once when the audio starts playing the first time and it will not be called next loops. Used internally as the "onPlayStart" parameter to call the "resume" method of the audio API object.
739 * @param {function} [onLoadError] - Function to be called if the audio cannot be played successfully. It will not be called if the audio is not paused or is stopped. The first and unique parameter will be a string describing the error found (if it could be determined), being "this" the {@link CB_AudioFile} object. Used internally as the "onLoadError" parameter to call the "resume" method of the audio API object.
740 * @returns {boolean|integer} Returns the returning value of the "resume" method of the audio API object. It returns false if the audio is not paused or it is stopped, returns "-1" if the audio cannot be played and an error is detected or returns true otherwise. Note that even when it returns true there can be a non-detectable error and maybe the audio is not played. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
741 */
742//CB_AudioFile.prototype.resume = function(stopAt, loop, /*startAtNextLoop,*/ allowOverlapping)
743CB_AudioFile.prototype.resume = function(loop, avoidDelayedPlay, allowedRecursiveDelay, onPlayStart, onLoadError)
744{
745 /////////if (typeof(loop) === "undefined" || loop === null) { loop = this.DEFAULT_OPTIONS.loop; }
746 if (typeof(loop) === "undefined" || loop === null) { loop = this.loop; } //If not set, uses the default (or last one used).
747 this.loop = loop;
748
749 //return this.audioFileObject.resume(stopAt, loop, /*startAtNextLoop,*/ allowOverlapping);
750
751 //Backups the parameters given:
752 this._avoidDelayedPlayLast = avoidDelayedPlay;
753 this._allowedRecursiveDelayLast = allowedRecursiveDelay;
754 //this._onPlayStartLast = onPlayStart;
755 this._onLoadErrorLast = onLoadError;
756
757 var that = this;
758
759 //Resumes the sound:
760 return this.audioFileObject.resume
761 (
762 loop,
763 avoidDelayedPlay,
764 allowedRecursiveDelay,
765 //////function() { if (typeof(onPlayStart) === "function") { onPlayStart.call(that); } },
766 function(startAt, stopAt, startAtNextLoop, loop, avoidDelayedPlay, allowedRecursiveDelay, startPlayingTime)
767 {
768 if (typeof(onPlayStart) === "function") { onPlayStart.call(that, startAt, stopAt, startAtNextLoop, loop, avoidDelayedPlay, allowedRecursiveDelay, startPlayingTime); }
769 },
770 function (error) { if (typeof(onPlayStart) === "function") { onLoadError.call(that, error); } }
771 );
772}
773
774
775/**
776 * Pauses the audio when it is being played. Internally, uses the "pause" method of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
777 * @function
778 * @param {function} [onPause] - Function without parameters to be called when the audio is paused successfully, being "this" the {@link CB_AudioFile} object. Used internally as the "onPause" parameter (with a wrapper function) to call the "pause" method of the audio API object.
779 * @param {boolean} [keepPausedUnaltered=false] - If set to true (not recommended), the "paused" property of the audio API object will not be set to true and it will remain with its current value. Used internally as the "keepPausedUnaltered" parameter to call the "pause" method of the audio API object.
780 * @returns {boolean} Returns the returning value of the "pause" method of the audio API object. It returns false if the audio is already paused or it is stopped or if it cannot be paused. Returns true otherwise. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
781 */
782CB_AudioFile.prototype.pause = function(onPause, keepPausedUnaltered)
783{
784 var that = this;
785 return this.audioFileObject.pause(function() { if (typeof(onPause) === "function") { onPause.call(that); } }, keepPausedUnaltered);
786}
787
788
789/**
790 * Stops the audio. Internally, uses the "stop" method of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
791 * @function
792 * @param {boolean} [keepStoppedUnaltered=false] - If set to true (not recommended), the "stopped" property of the audio API object will not be set to true and it will remain with its current value. Used internally as the "keepStoppedUnaltered" parameter to call the "stop" method of the audio API object.
793 * @param {boolean} [avoidOnStop=false] - If set to false and there is an "onStop" function defined (through the {@link CB_AudioFile#onStop} method), it will be called after stopping the audio (or after trying to do it, at least) but only if either the "forceOnStop" parameter is set to true or if the "keepStoppedUnaltered" parameter is set to false and the audio was not already stopped before. If set to true, the "onStop" function (if any) will not be called at all. Used internally as the "avoidOnStop" parameter to call the "stop" method of the audio API object.
794 * @param {boolean} [forceOnStop=false] - If it is set to true and the "avoidOnStop" parameter is set to false and there is an "onStop" function defined (through the {@link CB_AudioFile#onStop} method), it will be called regardless the audio was stopped before or not. If set to false, the "onStop" function (if any) will only be called if the "keepStoppedUnaltered" parameter is set to false and the audio was not already stopped before. This parameter will be ignored if the "avoidOnStop" parameter is set to true. Used internally as the "forceOnStop" parameter to call the "stop" method of the audio API object.
795 * @returns {boolean} Returns the returning value of the "stop" method of the audio API object. It returns false if the stopping action cannot be performed at all (this could happen with the internal audio API has not been loaded properly, for example). Returns true otherwise (this only means that it has been tried to be stopped but it could not be successfully). Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
796 */
797CB_AudioFile.prototype.stop = function(keepStoppedUnaltered, avoidOnStop, forceOnStop)
798{
799 return this.audioFileObject.stop(keepStoppedUnaltered, avoidOnStop, forceOnStop);
800}
801
802
803/**
804 * Returns the volume (from 0 to the maximum value, where the maximum value will be the returning value of calling the {@link CB_Speaker.getVolume} function if the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM} property is set to true or it will be 100 otherwise) that was set before the audio was muted. Internally, uses the "volumeBeforeMute" property of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
805 * @function
806 * @returns {number} Returns the volume (from 0 to the maximum value, where the maximum value will be the returning value of calling the {@link CB_Speaker.getVolume} function if the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM} property is set to true or it will be 100 otherwise) that was set before the audio was muted. If the audio was not muted before, it will contain the default volume used in the "volume" property of the used audio API object.
807 */
808CB_AudioFile.prototype.getVolumeBeforeMute = function()
809{
810 return this.audioFileObject.volumeBeforeMute;
811}
812
813
814/**
815 * Returns the current volume (from 0 to the maximum value, where the maximum value will be the returning value of calling the {@link CB_Speaker.getVolume} function if the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM} property is set to true or it will be 100 otherwise). Internally, uses the "volume" property of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
816 * @function
817 * @returns {number} Returns the current volume (from 0 to the maximum value, where the maximum value will be the returning value of calling the {@link CB_Speaker.getVolume} function if the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM} property is set to true or it will be 100 otherwise).
818 */
819CB_AudioFile.prototype.getVolume = function()
820{
821 this.volume = this.audioFileObject.volume;
822 return this.volume;
823}
824
825
826/**
827 * Sets the desired volume for the audio file (from 0 to the maximum value, where the maximum value will be the returning value of calling the {@link CB_Speaker.getVolume} function if the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM} property is set to true or it will be 100 otherwise). Internally, uses the "setVolume" method of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
828 * @function
829 * @param {number} [volume={@link CB_Speaker.getVolume()} | {@link CB_Configuration.CrossBase.CB_Speaker_DEFAULT_VOLUME}] - Desired volume (from 0 to the maximum value, where the maximum value will be the returning value of calling the {@link CB_Speaker.getVolume} function if the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM} property is set to true or it will be 100 otherwise). Used internally as the "volume" parameter to call the "setVolume" method of the audio API object.
830 * @param {boolean} [forceSetVolumeProperty=false] - If set to true (not recommended), it will change the "volume" property of the used audio API object even when the volume failed to be changed. Used internally as the "forceSetVolumeProperty" parameter to call the "setVolume" method of the audio API object.
831 * @param {function} [onSetVolume] - Callback function which will be called if it has been possible to set the volume (or at least it was possible to try it). It will not receive any parameters, being "this" the {@link CB_AudioFile} object. Used internally as the "onSetVolume" parameter (with a wrapper function) to call the "setVolume" method of the audio API object.
832 * @returns {number} Returns the current volume (from 0 to the maximum value, where the maximum value will be the returning value of calling the {@link CB_Speaker.getVolume} function if the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM} property is set to true or it will be 100 otherwise).
833 */
834CB_AudioFile.prototype.setVolume = function(volume, forceSetVolumeProperty, onSetVolume)
835{
836 var that = this;
837 this.volume = this.audioFileObject.setVolume(volume, forceSetVolumeProperty, function() { if (typeof(onSetVolume) === "function") { onSetVolume.call(that); } }, false);
838 return this.volume;
839}
840
841
842/**
843 * Mutes the audio file. Internally, uses the "mute" method of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
844 * @function
845 * @param {function} [onMute] - Callback function which will be called if it has been possible to mute the audio file (or at least it was possible to try it). It will not receive any parameters, being "this" the {@link CB_AudioFile} object. Used internally as the "onMute" parameter (with a wrapper function) to call the "mute" method of the audio API object.
846 * @returns {number} Returns the current volume (from 0 to the maximum value, where the maximum value will be the returning value of calling the {@link CB_Speaker.getVolume} function if the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM} property is set to true or it will be 100 otherwise). If all goes well, the returning value should be zero (0). Note that, even when it returns a zero (0) value, this does not always mean that the mute has been applied successfully.
847 */
848CB_AudioFile.prototype.mute = function(onMute)
849{
850 var that = this;
851 this.volume = this.audioFileObject.mute(function() { if (typeof(onMute) === "function") { onMute.call(that); } });
852 return this.volume;
853}
854
855
856/**
857 * Restores audio after muting it (unmutes it). Internally, uses the "unmute" method of the used audio API object which uses its own "volumeBeforeMute" property. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
858 * @function
859 * @param {function} [onUnmute] - Callback function which will be called if it has been possible to unmute the audio file (or at least it was possible to try it). It will not receive any parameters, being "this" the {@link CB_AudioFile} object. Used internally as the "onUnmute" parameter (with a wrapper function) to call the "unmute" method of the audio API object.
860 * @returns {number} Returns the current volume (from 0 to the maximum value, where the maximum value will be the returning value of calling the {@link CB_Speaker.getVolume} function if the {@link CB_Configuration.CrossBase.CB_AudioFile_AudioFileCache_USE_SPEAKER_VOLUME_AS_MAXIMUM} property is set to true or it will be 100 otherwise).
861 */
862CB_AudioFile.prototype.unmute = function(onUnmute)
863{
864 var that = this;
865 this.volume = this.audioFileObject.unmute(function() { if (typeof(onUnmute) === "function") { onUnmute.call(that); } });
866 return this.volume;
867}
868
869
870/**
871 * Gets the current time (in milliseconds) which belongs to the position where the audio is currently playing or where it has been paused. Note that some audio APIs and clients could give wrong values. Internally, uses the "getCurrentTime" method of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
872 * @function
873 * @returns {number} Returns the current time (in milliseconds). Note that some audio APIs and clients could give wrong values.
874 */
875CB_AudioFile.prototype.getCurrentTime = function()
876{
877 return this.audioFileObject.getCurrentTime();
878}
879
880
881/**
882 * Gets the current status of the audio file.
883 * @function
884 * @param {boolean} [realStatus=false] - If set to true, it will return the "status" property of the used audio API object instead of the "status" property of the current CB_AudioFile object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
885 * @returns {number} Returns the current status of the audio file. It is a number, which should match the value of the CB_AudioFile.UNLOADED (still unloaded), CB_AudioFile.LOADING (loading), CB_AudioFile.UNCHECKED (not checked by calling the "checkPlaying" method yet), CB_AudioFile.CHECKING (being checked by the "checkPlaying" method), CB_AudioFile.LOADED (loaded), CB_AudioFile.FAILED (failed loading or failed to play or by any other reason) or CB_AudioFile.ABORTED (aborted because it was destroyed with the "destructor" method) property.
886 */
887CB_AudioFile.prototype.getStatus = function(realStatus)
888{
889 if (this._loadingAudioFileObject &amp;&amp; !realStatus) { return CB_AudioFile.LOADING; }
890 return this.audioFileObject.status;
891}
892
893
894/**
895 * Gets the current status of the audio file, as a string.
896 * @function
897 * @param {boolean} [realStatus=false] - If set to true, it will have in mind the "status" property of the used audio API object instead of the "status" property of the current CB_AudioFile object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
898 * @returns {string} Returns the current status of the audio file, as a string. Possible return values are "UNLOADED", "LOADING", "UNCHECKED", "CHECKING", "LOADED", "FAILED", "ABORTED" or "UNKNOWN (UNKNOWN_STATUS)" (where "UNKNOWN_STATUS" will be a value from the "status" property not recognized as any possible status).
899 */
900CB_AudioFile.prototype.getStatusString = function(realStatus)
901{
902 var status = this.getStatus(realStatus);
903 var statuses = [ "UNLOADED", "LOADING", "UNCHECKED", "CHECKING", "LOADED", "FAILED", "ABORTED" ];
904 if (typeof(statuses[status]) !== "undefined") { return statuses[status]; }
905 else { return "UNKNOWN (" + status + ")"; }
906}
907
908
909/**
910 * Tells whether the audio file is playing or not. Internally, uses the {@link CB_AudioFile#isStopped} and {@link CB_AudioFile#isPaused} methods.
911 * @function
912 * @returns {boolean} Returns whether the audio file is playing or not.
913 */
914CB_AudioFile.prototype.isPlaying = function()
915{
916 return (!this.isStopped() &amp;&amp; !this.isPaused());
917}
918
919
920/**
921 * Tells whether the audio is paused or not. Internally, uses the "paused" property of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
922 * @function
923 * @returns {boolean} Returns whether the audio is paused or not.
924 */
925CB_AudioFile.prototype.isPaused = function()
926{
927 return this.audioFileObject.paused;
928}
929
930
931/**
932 * Tells whether the audio file is stopped or not. Internally, uses the "stopped" property of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
933 * @function
934 * @returns {boolean} Returns whether the audio file is stopped or not.
935 */
936CB_AudioFile.prototype.isStopped = function()
937{
938 return this.audioFileObject.stopped;
939}
940
941
942/*
943//Returns the bytes loaded of the file:
944CB_AudioFile.prototype.getBytesLoaded = function()
945{
946 return this.audioFileObject.getBytesLoaded();
947}
948
949
950//Returns the total bytes of the file:
951CB_AudioFile.prototype.getBytesTotal = function()
952{
953 return this.audioFileObject.getBytesTotal();
954}
955*/
956
957/**
958 * Sets a function to execute when the audio file stops playing or removes it. Internally, uses the "onStop" method of the used audio API object (wrapping the given function).
959 * @function
960 * @param {function|null} callbackFunction - The function (event listener) that we want to execute when the event is fired. No parameters will be received, being "this" the {@link CB_AudioFile} object. If a null value is used, the event will be removed.
961 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener or not.
962 * @returns {boolean} Returns whether the event has been set or not (removed).
963 */
964CB_AudioFile.prototype.onStop = function(callbackFunction, keepOldFunction)
965{
966 //If not set, it keeps old function by default:
967 if (typeof(keepOldFunction) === "undefined" || keepOldFunction === null) { keepOldFunction = true; }
968
969 if (typeof(callbackFunction) !== "function") { this._onStopFunction = null; return false; }
970
971 var that = this;
972
973 //If we don't want to keep the old function:
974 if (!keepOldFunction)
975 {
976 this._onStopFunction = callbackFunction;
977 }
978 //...otherwise if we want to keep the old function, we keep it:
979 else
980 {
981 //Stores old function:
982 var oldFunction = this._onStopFunction; //Stores old function of eventFunctionHolder.
983 this._onStopFunction =
984 function()
985 {
986 if (typeof(oldFunction) === "function") { oldFunction.call(that); }
987 callbackFunction.call(that);
988 };
989 }
990
991 ////return this.audioFileObject.onStop(callbackFunction, false); //We have already kept the function (if desired).
992 return this.audioFileObject.onStop(function() { if (typeof(that._onStopFunction) === "function") { that._onStopFunction.call(that); } }, false); //We have already kept the function (if desired).
993}
994
995
996/**
997 * Tells the last "startAt" parameter value used by the {@link CB_AudioFile#play} or the {@link CB_AudioFile#resume} method (or used by the equivalents methods of the same name from the used audio API object). Internally, uses the "lastStartAt" property of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
998 * @function
999 * @param {boolean} [numeric=false] - If set to true, it will sanitize the returning value by returning zero instead of undefined, null or any other non-numeric value.
1000 * @returns {number|*} Returns the last "startAt" value used by the {@link CB_AudioFile#play} or the {@link CB_AudioFile#resume} method (or used by the equivalents methods of the same name from the used audio API object). If we want it to be numeric always, the "numeric" parameter should be set to true.
1001 */
1002CB_AudioFile.prototype.getStartAt = function(numeric)
1003{
1004 var value = undefined;
1005 if (typeof(this.audioFileObject.lastStartAt) !== "undefined") { value = this.audioFileObject.lastStartAt; }
1006 if (numeric &amp;&amp; (typeof(value) === "undefined" || value === null || isNaN(value))) { value = 0; }
1007 return value;
1008}
1009
1010
1011/**
1012 * Tells the last "stopAt" parameter value used by the {@link CB_AudioFile#play} or the {@link CB_AudioFile#resume} method (or used by the equivalents methods of the same name from the used audio API object). Internally, uses the "lastStopAt" property of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
1013 * @function
1014 * @param {boolean} [numeric=false] - If set to true, it will sanitize the returning value by returning zero instead of undefined, null or any other non-numeric value.
1015 * @returns {number|*} Returns the last "stopAt" value used by the {@link CB_AudioFile#play} or the {@link CB_AudioFile#resume} method (or used by the equivalents methods of the same name from the used audio API object). If we want it to be numeric always, the "numeric" parameter should be set to true.
1016 */
1017CB_AudioFile.prototype.getStopAt = function(numeric)
1018{
1019 var value = undefined;
1020 if (typeof(this.audioFileObject.lastStopAt) !== "undefined") { value = this.audioFileObject.lastStopAt; }
1021 if (numeric &amp;&amp; (typeof(value) === "undefined" || value === null || isNaN(value))) { value = 0; }
1022 return value;
1023}
1024
1025
1026/**
1027 * Returns a number representing the percentage of the loading progress for the audio file (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. Internally, uses the "getProgress" method of the used audio API object. Possible internal audio API objects are {@link CB_AudioFile_API.WAAPI} object for "WAAPI" ([HTML5 Web Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API}), {@link CB_AudioFile_API.SM2} object for "SM2" ([SoundManager 2]{@link http://schillmania.com/projects/soundmanager2/}), {@link CB_AudioFile_API.ACMP} object for "ACMP" ([Apache Cordova Media Plugin]{@link https://github.com/apache/cordova-plugin-media}) or {@link CB_AudioFile_API.AAPI} object for "AAPI" ([HTML5 Audio API]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio}).
1028 * @function
1029 * @returns {number} Returns a number representing the percentage of the loading progress for the audio file (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.
1030 */
1031CB_AudioFile.prototype.getProgress = function()
1032{
1033 return this.audioFileObjectLast.getProgress();
1034}</pre>
1035 </article>
1036</section>
1037
1038
1039
1040
1041
1042 </div>
1043 </div>
1044
1045 <div class="clearfix"></div>
1046
1047
1048
1049</div>
1050</div>
1051
1052
1053 <div class="modal fade" id="searchResults">
1054 <div class="modal-dialog">
1055 <div class="modal-content">
1056 <div class="modal-header">
1057 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
1058 <h4 class="modal-title">Search results</h4>
1059 </div>
1060 <div class="modal-body"></div>
1061 <div class="modal-footer">
1062 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
1063 </div>
1064 </div><!-- /.modal-content -->
1065 </div><!-- /.modal-dialog -->
1066 </div>
1067
1068
1069<footer>
1070
1071
1072 <span class="copyright">
1073 <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>
1074 </span>
1075
1076<span class="jsdoc-message">
1077 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
1078
1079 on Mon Feb 3rd 2020
1080
1081 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
1082</span>
1083</footer>
1084
1085<script src="scripts/docstrap.lib.js"></script>
1086<script src="scripts/toc.js"></script>
1087
1088 <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
1089
1090
1091<script>
1092$( function () {
1093 $( "[id*='$']" ).each( function () {
1094 var $this = $( this );
1095
1096 $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
1097 } );
1098
1099 $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
1100 var $this = $( this );
1101
1102 var example = $this.find( "code" );
1103 exampleText = example.html();
1104 var lang = /{@lang (.*?)}/.exec( exampleText );
1105 if ( lang && lang[1] ) {
1106 exampleText = exampleText.replace( lang[0], "" );
1107 example.html( exampleText );
1108 lang = lang[1];
1109 } else {
1110 var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
1111 lang = langClassMatch ? langClassMatch[1] : "javascript";
1112 }
1113
1114 if ( lang ) {
1115
1116 $this
1117 .addClass( "sunlight-highlight-" + lang )
1118 .addClass( "linenums" )
1119 .html( example.html() );
1120
1121 }
1122 } );
1123
1124 Sunlight.highlightAll( {
1125 lineNumbers : true,
1126 showMenu : true,
1127 enableDoclinks : true
1128 } );
1129
1130 $.catchAnchorLinks( {
1131 navbarOffset: 10
1132 } );
1133 $( "#toc" ).toc( {
1134 anchorName : function ( i, heading, prefix ) {
1135 return $( heading ).attr( "id" ) || ( prefix + i );
1136 },
1137 selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
1138 showAndHide : false,
1139 smoothScrolling: true
1140 } );
1141
1142 $( "#main span[id^='toc']" ).addClass( "toc-shim" );
1143 $( '.dropdown-toggle' ).dropdown();
1144
1145 $( "table" ).each( function () {
1146 var $this = $( this );
1147 $this.addClass('table');
1148 } );
1149
1150} );
1151</script>
1152
1153
1154
1155<!--Navigation and Symbol Display-->
1156
1157<script>
1158 $( function () {
1159 $( '#main' ).localScroll( {
1160 offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
1161 } );
1162 $( "dt.name" ).each( function () {
1163 var $this = $( this ).find("h4");
1164 var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
1165 var dt = $(this);
1166 var children = dt.next( "dd" );
1167
1168 dt.prepend( icon ).css( {cursor : "pointer"} );
1169 dt.addClass( "member-collapsed" ).addClass( "member" );
1170
1171
1172 children.hide();
1173
1174 dt.children().on( "click", function () {
1175 children = dt.next( "dd" );
1176 children.slideToggle( "fast", function () {
1177
1178 if ( children.is( ":visible" ) ) {
1179 icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
1180 dt.addClass( "member-open" ).animate( "member-collapsed" );
1181 } else {
1182 icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
1183 dt.addClass( "member-collapsed" ).removeClass( "member-open" );
1184 }
1185 } );
1186 } );
1187
1188 } );
1189 } );
1190</script>
1191
1192
1193<!--Google Analytics-->
1194
1195
1196
1197 <script type="text/javascript">
1198 $(document).ready(function() {
1199 SearcherDisplay.init();
1200 });
1201 </script>
1202
1203
1204</body>
1205</html>