Skip to content

Commit 6481872

Browse files
Added method for creating loop buffer source
1 parent d788ed3 commit 6481872

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

v3/src/sound/webaudio/WebAudioSound.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ var WebAudioSound = new Class({
134134
this.source.start(0, Math.max(0, offset), Math.max(0, duration));
135135
this.resetConfig();
136136
},
137+
/**
138+
* @private
139+
*/
140+
createLoopBufferSource: function () {
141+
this.loopSource = this.manager.context.createBufferSource();
142+
this.loopSource.buffer = this.audioBuffer;
143+
this.loopSource.connect(this.muteNode);
144+
this.loopSource.onended = function (ev) {
145+
if (ev.target === this.source) {
146+
// sound ended
147+
this.hasEnded = true;
148+
}
149+
// else was stopped
150+
}.bind(this);
151+
},
137152
/**
138153
* Used internally to do what the name says.
139154
*
@@ -191,6 +206,9 @@ var WebAudioSound = new Class({
191206
if (this.source) {
192207
this.source.playbackRate.setValueAtTime(this.totalRate, 0);
193208
}
209+
if (this.loopSource) {
210+
this.loopSource.playbackRate.setValueAtTime(this.totalRate, 0);
211+
}
194212
if (this.isPlaying) {
195213
this.rateUpdates.push({
196214
time: this.manager.context.currentTime - this.startTime,

0 commit comments

Comments
 (0)