Skip to content

Commit 685c4e6

Browse files
committed
update howler to 1.0.7, code implementation complete
1 parent 56959a1 commit 685c4e6

File tree

3 files changed

+45
-33
lines changed

3 files changed

+45
-33
lines changed

HowlerAudioEngine.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ cc.HowlerAudioEngine = cc.AudioEngine.extend(/** @lends cc.AudioEngine# */{
8686
}
8787
this._playingMusic = keyname;
8888

89-
if (this._effectList.hasOwnProperty(keyname)) {
89+
if (this._muiscList.hasOwnProperty(keyname)) {
9090
au = this._muiscList[keyname];
9191
} else {
9292
au = new Howl({
@@ -214,24 +214,19 @@ cc.HowlerAudioEngine = cc.AudioEngine.extend(/** @lends cc.AudioEngine# */{
214214
this._effectList[keyname] = au;
215215
}
216216

217+
//to prevent a bug. when one effect plays in a loop,
218+
//no effect of the same type can play at the same time
219+
if (au.loop()) {
220+
return keyname;
221+
}
222+
217223
if (loop) {
218224
au.loop(loop);
219225
}
220226
au.play();
221227
return keyname;
222228
},
223229

224-
/**
225-
*The volume of the effects max value is 1.0,the min value is 0.0 .
226-
* @return {Number}
227-
* @example
228-
* //example
229-
* var effectVolume = cc.AudioEngine.getInstance().getEffectsVolume();
230-
*/
231-
getEffectsVolume:function () {
232-
return this._effectList[0].volume();
233-
},
234-
235230
/**
236231
* Set the volume of sound effecs.
237232
* @param {Number} volume Volume must be in 0.0~1.0 .
@@ -250,8 +245,10 @@ cc.HowlerAudioEngine = cc.AudioEngine.extend(/** @lends cc.AudioEngine# */{
250245
this._effectsVolume = volume;
251246
}
252247

253-
for (var i = this._effectList.length - 1; i >= 0; i--) {
254-
this._effectList[i].volume(volume);
248+
for (var key in this._effectList) {
249+
if (this._effectList.hasOwnProperty(key)) {
250+
this._effectList[key].volume(volume);
251+
}
255252
}
256253
},
257254

@@ -265,7 +262,7 @@ cc.HowlerAudioEngine = cc.AudioEngine.extend(/** @lends cc.AudioEngine# */{
265262
pauseEffect:function (path) {
266263
var keyname = this._getPathWithoutExt(path);
267264
if (this._effectList.hasOwnProperty(keyname)) {
268-
this._effectList[keyname].pause();
265+
this._effectList[keyname].loop(false).pause();
269266
}
270267
},
271268

@@ -276,8 +273,10 @@ cc.HowlerAudioEngine = cc.AudioEngine.extend(/** @lends cc.AudioEngine# */{
276273
* cc.AudioEngine.getInstance().pauseAllEffects();
277274
*/
278275
pauseAllEffects:function () {
279-
for (var i = this._effectList.length - 1; i >= 0; i--) {
280-
this._effectList[i].pause();
276+
for (var key in this._effectList) {
277+
if (this._effectList.hasOwnProperty(key)) {
278+
this._effectList[key].loop(false).pause();
279+
}
281280
}
282281
},
283282

@@ -302,8 +301,10 @@ cc.HowlerAudioEngine = cc.AudioEngine.extend(/** @lends cc.AudioEngine# */{
302301
* cc.AudioEngine.getInstance().resumeAllEffects();
303302
*/
304303
resumeAllEffects:function () {
305-
for (var i = this._effectList.length - 1; i >= 0; i--) {
306-
this._effectList[i].play();
304+
for (var key in this._effectList) {
305+
if (this._effectList.hasOwnProperty(key)) {
306+
this._effectList[key].play();
307+
}
307308
}
308309
},
309310

@@ -317,7 +318,7 @@ cc.HowlerAudioEngine = cc.AudioEngine.extend(/** @lends cc.AudioEngine# */{
317318
stopEffect:function (path) {
318319
var keyname = this._getPathWithoutExt(path);
319320
if (this._effectList.hasOwnProperty(keyname)) {
320-
this._effectList[keyname].stop();
321+
this._effectList[keyname].loop(false).stop();
321322
}
322323
},
323324

@@ -328,8 +329,10 @@ cc.HowlerAudioEngine = cc.AudioEngine.extend(/** @lends cc.AudioEngine# */{
328329
* cc.AudioEngine.getInstance().stopAllEffects();
329330
*/
330331
stopAllEffects:function () {
331-
for (var i = this._effectList.length - 1; i >= 0; i--) {
332-
this._effectList[i].stop();
332+
for (var key in this._effectList) {
333+
if (this._effectList.hasOwnProperty(key)) {
334+
this._effectList[key].loop(false).stop();
335+
}
333336
}
334337
}
335338

howler/howler.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* howler.js v1.0.6
2+
* howler.js v1.0.7
33
* howlerjs.com
44
*
55
* (c) 2013, James Simpson of GoldFire Studios
@@ -44,7 +44,7 @@
4444
volume: function(vol) {
4545
var self = this;
4646

47-
if (vol >= 0 && vol <= 1) {
47+
if (vol && vol >= 0 && vol <= 1) {
4848
self._volume = vol;
4949

5050
if (usingWebAudio) {
@@ -126,7 +126,7 @@
126126
// allow access to the global audio controls
127127
window.Howler = new HowlerGlobal();
128128

129-
// chek for browser codec support
129+
// check for browser codec support
130130
var audioTest = new Audio();
131131
var codecs = {
132132
mp3: !!audioTest.canPlayType('audio/mpeg;').replace(/^no$/,''),
@@ -321,12 +321,15 @@
321321

322322
// end the track if it is HTML audio
323323
if (!self._webAudio) {
324-
self.pause(data.id);
324+
self.pause(data.id, data.timer);
325325
}
326326

327327
// fire ended event
328328
self.on('end');
329329
}, duration * 1000));
330+
331+
// remember which timer to cancel
332+
data.timer = self._onendTimer[self._onendTimer.length - 1];
330333
})();
331334

332335
if (self._webAudio) {
@@ -349,9 +352,10 @@
349352
/**
350353
* Pause playback and save the current position.
351354
* @param {String} id (optional) Used only for HTML5 Audio to pause specific node.
355+
* @param {String} id (optional) Used only for HTML5 Audio to clear the correct timeout id.
352356
* @return {Object}
353357
*/
354-
pause: function(id) {
358+
pause: function(id, timerId) {
355359
var self = this;
356360

357361
// if the sound hasn't been loaded, add it to the event queue
@@ -364,9 +368,10 @@
364368
}
365369

366370
// clear 'onend' timer
367-
if (self._onendTimer[0]) {
368-
clearTimeout(self._onendTimer[0]);
369-
self._onendTimer.splice(0, 1);
371+
var timer = self._onendTimer.indexOf(timerId);
372+
if (timer >= 0) {
373+
clearTimeout(self._onendTimer[timer]);
374+
self._onendTimer.splice(timer, 1);
370375
}
371376

372377
if (self._webAudio) {
@@ -846,7 +851,11 @@
846851
var loadBuffer = function(obj, url) {
847852
// check if the buffer has already been cached
848853
if (url in cache) {
849-
loadSound(obj, cache[url]);
854+
// set the duration from the cache
855+
obj._duration = cache[url].duration;
856+
857+
// load the sound into this object
858+
loadSound(obj);
850859
} else {
851860
// load the buffer from the URL
852861
var xhr = new XMLHttpRequest();

0 commit comments

Comments
 (0)