diff --git a/src/audio/Audio.js b/src/audio/Audio.js index 9e5fd28e25ae10427924e5ba194cddbd5f206f6a..b1bf99d1a2593330cc16cdee6e6e43c7e7ac9b13 100644 --- a/src/audio/Audio.js +++ b/src/audio/Audio.js @@ -12,14 +12,14 @@ function Audio( listener ) { this.type = 'Audio'; this.context = listener.context; - this.source = this.context.createBufferSource(); - this.source.onended = this.onEnded.bind( this ); this.gain = this.context.createGain(); this.gain.connect( listener.getInput() ); this.autoplay = false; + this.buffer = null; + this.loop = false; this.startTime = 0; this.playbackRate = 1; this.isPlaying = false; @@ -53,7 +53,7 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), { setBuffer: function ( audioBuffer ) { - this.source.buffer = audioBuffer; + this.buffer = audioBuffer; this.sourceType = 'buffer'; if ( this.autoplay ) this.play(); @@ -80,9 +80,9 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), { var source = this.context.createBufferSource(); - source.buffer = this.source.buffer; - source.loop = this.source.loop; - source.onended = this.source.onended; + source.buffer = this.buffer; + source.loop = this.loop; + source.onended = this.onEnded.bind( this ); source.start( 0, this.startTime ); source.playbackRate.value = this.playbackRate; @@ -256,7 +256,7 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), { } - return this.source.loop; + return this.loop; }, @@ -269,7 +269,15 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), { } - this.source.loop = value; + this.loop = value; + + if ( this.isPlaying === true ) { + + this.source.loop = this.loop; + + } + + return this; },