Browse Source

Sound Update

sebavan 5 năm trước cách đây
mục cha
commit
bc73e4b235
1 tập tin đã thay đổi với 20 bổ sung2 xóa
  1. 20 2
      src/Audio/sound.ts

+ 20 - 2
src/Audio/sound.ts

@@ -747,9 +747,11 @@ export class Sound {
                             offset = offset || this._offset;
 
                             if (this._soundSource) {
-                                this._soundSource.stop();
+                                const oldSource = this._soundSource;
+                                oldSource.onended = () => {
+                                    oldSource.disconnect();
+                                };
                             }
-
                             this._soundSource = Engine.audioEngine.audioContext.createBufferSource();
                             this._soundSource.buffer = this._audioBuffer;
                             this._soundSource.connect(this._inputAudioNode);
@@ -1001,6 +1003,22 @@ export class Sound {
     }
 
     /**
+     * Gets the WebAudio AudioBufferSourceNode, lets you keep track of and stop instances of this Sound.
+     * @returns the source node
+     */
+    public getSoundSource(): Nullable<AudioBufferSourceNode> {
+        return this._soundSource;
+    }
+
+    /**
+     * Gets the WebAudio GainNode, gives you precise control over the gain of instances of this Sound.
+     * @returns the gain node
+     */
+    public getSoundGain(): Nullable<GainNode> {
+        return this._soundGain;
+    }
+
+    /**
      * Serializes the Sound in a JSON representation
      * @returns the JSON representation of the sound
      */