Przeglądaj źródła

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 7 lat temu
rodzic
commit
f87026e587
3 zmienionych plików z 372 dodań i 247 usunięć
  1. 342 241
      src/Audio/babylon.audioEngine.ts
  2. 22 1
      src/Audio/babylon.sound.ts
  3. 8 5
      src/Tools/babylon.tools.ts

Plik diff jest za duży
+ 342 - 241
src/Audio/babylon.audioEngine.ts


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

@@ -560,7 +560,28 @@ module BABYLON {
                         this._streamingSource.disconnect();
                         this._streamingSource.connect(this._inputAudioNode);
                         if (this._htmlAudioElement) {
-                            this._htmlAudioElement.play();
+                            // required to manage properly the new suspended default state of Chrome
+                            // When the option 'streaming: true' is used, we need first to wait for
+                            // the audio engine to be unlocked by a user gesture before trying to play
+                            // an HTML Audio elememt
+                            var tryToPlay = () => {
+                                if (Engine.audioEngine.unlocked) {
+                                    var playPromise = this._htmlAudioElement.play();
+
+                                    // In browsers that don’t yet support this functionality,
+                                    // playPromise won’t be defined.
+                                    if (playPromise !== undefined) {
+                                        playPromise.catch(function(error) {
+                                        // Automatic playback failed.
+                                        // Waiting for the audio engine to be unlocked by user click on unmute
+                                        });
+                                    }
+                                }
+                                else {
+                                    window.setTimeout(tryToPlay, 500);
+                                }
+                            }
+                            tryToPlay();
                         }
                     }
                     else {

+ 8 - 5
src/Tools/babylon.tools.ts

@@ -1951,14 +1951,15 @@
          * Defines the current index of the loop.
          */
         public index: number;
-
         private _done: boolean;
+        private _fn: (asyncLoop: AsyncLoop) => void;
+        private _successCallback: () => void;
 
         /**
          * Constructor.
          * @param iterations the number of iterations.
-         * @param _fn the function to run each iteration
-         * @param _successCallback the callback that will be called upon succesful execution
+         * @param func the function to run each iteration
+         * @param successCallback the callback that will be called upon succesful execution
          * @param offset starting offset.
          */
         constructor(
@@ -1966,12 +1967,14 @@
              * Defines the number of iterations for the loop
              */
             public iterations: number, 
-            private _fn: (asyncLoop: AsyncLoop) => void, 
-            private _successCallback: () => void, 
+            func: (asyncLoop: AsyncLoop) => void, 
+            successCallback: () => void, 
             offset: number = 0) {
 
             this.index = offset - 1;
             this._done = false;
+            this._fn = func;
+            this._successCallback = successCallback;
         }
 
         /**