Explorar o código

Audio Same Player Try Again... Insert Coins

sebastien %!s(int64=7) %!d(string=hai) anos
pai
achega
6a473fdf25
Modificáronse 1 ficheiros con 12 adicións e 2 borrados
  1. 12 2
      src/Audio/babylon.audioEngine.ts

+ 12 - 2
src/Audio/babylon.audioEngine.ts

@@ -243,9 +243,15 @@
             }
             }
         }
         }
 
 
+        private _tryToRun = false;
         private _triggerRunningState() {
         private _triggerRunningState() {
+            if (this._tryToRun) {
+                return;
+            }
+            this._tryToRun = true;
             this._resumeAudioContext()
             this._resumeAudioContext()
                 .then(() => {
                 .then(() => {
+                    this._tryToRun = false;
                     this.unlocked = true;
                     this.unlocked = true;
                     if (this._muteButton) {
                     if (this._muteButton) {
                         this._hideMuteButton(); 
                         this._hideMuteButton(); 
@@ -254,6 +260,7 @@
                     // Notify users that the audio stack is unlocked/unmuted
                     // Notify users that the audio stack is unlocked/unmuted
                     this.onAudioUnlockedObservable.notifyObservers(this);
                     this.onAudioUnlockedObservable.notifyObservers(this);
                 }).catch(() => {
                 }).catch(() => {
+                    this._tryToRun = false;
                     this.unlocked = false;
                     this.unlocked = false;
                 });
                 });
         }
         }
@@ -287,10 +294,13 @@
 
 
             this._muteButton.addEventListener('mousedown', () => { 
             this._muteButton.addEventListener('mousedown', () => { 
                 this._triggerRunningState();
                 this._triggerRunningState();
-            }, false);
+            }, true);
             this._muteButton.addEventListener('touchend', () => { 
             this._muteButton.addEventListener('touchend', () => { 
                 this._triggerRunningState();
                 this._triggerRunningState();
-            }, false);
+            }, true);
+            this._muteButton.addEventListener('click', () => {
+                this._triggerRunningState();
+            }, true);
 
 
             window.addEventListener("resize", this._onResize);
             window.addEventListener("resize", this._onResize);
         }
         }