Просмотр исходного кода

Merge pull request #5171 from sebavan/master

ios audio
sebavan 7 лет назад
Родитель
Сommit
c27f08efd3
2 измененных файлов с 9 добавлено и 38 удалено
  1. 8 38
      src/Audio/babylon.audioEngine.ts
  2. 1 0
      src/Audio/babylon.sound.ts

+ 8 - 38
src/Audio/babylon.audioEngine.ts

@@ -186,10 +186,6 @@
             catch (e) {
                 // protect error during capability check.
             }
-
-            if (/iPad|iPhone|iPod/.test(navigator.platform)) {
-                this._unlockiOSaudio();
-            }
         }
 
         /** 
@@ -208,34 +204,6 @@
             this._triggerRunningState();
         }
 
-        private _unlockiOSaudio() {
-            this._displayMuteButton(true);
-
-            var unlockaudio = () => {
-                if (!this.audioContext) {
-                    return;
-                }
-                var buffer = this.audioContext.createBuffer(1, 1, 22050);
-                var source = this.audioContext.createBufferSource();
-                source.buffer = buffer;
-                source.connect(this.audioContext.destination);
-                source.start(0);
-  
-                setTimeout(() => {
-                    if (((<any>source).playbackState === (<any>source).PLAYING_STATE || (<any>source).playbackState === (<any>source).FINISHED_STATE)) { 
-                        this._triggerRunningState();
-                        if (this._muteButton) {
-                            this._muteButton.removeEventListener('touchend', unlockaudio, false);
-                        }
-                    }
-                }, 0);
-            };
-
-            if (this._muteButton) {
-                this._muteButton.addEventListener('touchend', unlockaudio, false);
-            }
-        }
-
         private _resumeAudioContext() {
             if (this._audioContext!.resume) {
                 this._audioContext!.resume();
@@ -293,7 +261,7 @@
             this._displayMuteButton();
         }
 
-        private _displayMuteButton(iOS: boolean = false) {
+        private _displayMuteButton() {
             if (this.useCustomUnlockedButton) {
                 return;
             }
@@ -314,11 +282,13 @@
 
             this._moveButtonToTopLeft();
 
-            if (!iOS) {
-                this._muteButton.addEventListener('mousedown', () => { 
-                    this._triggerRunningState(); 
-                }, false);
-            }
+            this._muteButton.addEventListener('mousedown', () => { 
+                this._triggerRunningState();
+            }, false);
+            this._muteButton.addEventListener('touchend', () => { 
+                this._triggerRunningState();
+            }, false);
+
             this._muteButtonDisplayed = true;
 
             window.addEventListener("resize", this._onResize);

+ 1 - 0
src/Audio/babylon.sound.ts

@@ -214,6 +214,7 @@ module BABYLON {
                                                 }
                                             });
                                             document.body.appendChild(this._htmlAudioElement);
+                                            this._htmlAudioElement.load();
                                         }
                                         break;
                                     }