From bcb11d5c4e0cb82610c82cf281a5da019366418d Mon Sep 17 00:00:00 2001 From: Pavle Goloskokovic Date: Wed, 17 Jan 2018 18:24:03 +0100 Subject: [PATCH] Moved queued sound actions logic from update method to unlocked event handler --- src/sound/html5/HTML5AudioSoundManager.js | 53 ++++++++++------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/src/sound/html5/HTML5AudioSoundManager.js b/src/sound/html5/HTML5AudioSoundManager.js index 2105083bf..a1067b12b 100644 --- a/src/sound/html5/HTML5AudioSoundManager.js +++ b/src/sound/html5/HTML5AudioSoundManager.js @@ -92,6 +92,30 @@ var HTML5AudioSoundManager = new Class({ tag.load(); }); }; + this.once('unlocked', function () { + var allSoundsTouchLockedActionQueue = []; + _this.forEachActiveSound(function (sound) { + sound.touchLockedActionQueue.forEach(function (touchLockedAction) { + allSoundsTouchLockedActionQueue.push(touchLockedAction); + }); + sound.touchLockedActionQueue.length = 0; + sound.touchLockedActionQueue = null; + // TODO set correct duration value + }); + allSoundsTouchLockedActionQueue.sort(function (tla1, tla2) { + return tla1.time - tla2.time; + }); + allSoundsTouchLockedActionQueue.forEach(function (touchLockedAction) { + switch (touchLockedAction.type) { + case 'method': + touchLockedAction.sound[touchLockedAction.name].apply(touchLockedAction.sound, touchLockedAction.value || []); + break; + case 'property': + touchLockedAction.sound[touchLockedAction.name] = touchLockedAction.value; + break; + } + }); + }); document.body.addEventListener('touchend', unlock, false); }, onBlur: function () { @@ -108,35 +132,6 @@ var HTML5AudioSoundManager = new Class({ }); this.onBlurPausedSounds.length = 0; }, - update: function () { - if (this.touchUnlocked) { - this.touchUnlocked = false; - this.touchLocked = false; - var allSoundsTouchLockedActionQueue_1 = []; - this.forEachActiveSound(function (sound) { - sound.touchLockedActionQueue.forEach(function (touchLockedAction) { - allSoundsTouchLockedActionQueue_1.push(touchLockedAction); - }); - sound.touchLockedActionQueue.length = 0; - sound.touchLockedActionQueue = null; - // TODO set correct duration value - }); - allSoundsTouchLockedActionQueue_1.sort(function (tla1, tla2) { - return tla1.time - tla2.time; - }); - allSoundsTouchLockedActionQueue_1.forEach(function (touchLockedAction) { - switch (touchLockedAction.type) { - case 'method': - touchLockedAction.sound[touchLockedAction.name].apply(touchLockedAction.sound, touchLockedAction.value || []); - break; - case 'property': - touchLockedAction.sound[touchLockedAction.name] = touchLockedAction.value; - break; - } - }); - } - BaseSoundManager.prototype.update.call(this); - }, destroy: function () { BaseSoundManager.prototype.destroy.call(this); this.onBlurPausedSounds.length = 0;