Skip to content

Commit 1fe58bc

Browse files
Refactored update method looping and ending logic a bit
1 parent 2a70eb9 commit 1fe58bc

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/sound/html5/HTML5AudioSound.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,26 @@ var HTML5AudioSound = new Class({
196196
var startTime = this.currentMarker ? this.currentMarker.start : 0;
197197
var endTime = startTime + this.duration;
198198
var currentTime = this.audio.currentTime;
199-
if (this.currentConfig.loop && currentTime >= endTime - this.manager.loopEndOffset) {
200-
this.audio.currentTime = startTime + Math.max(0, currentTime - endTime);
201-
currentTime = this.audio.currentTime;
199+
if (this.currentConfig.loop) {
200+
if (currentTime >= endTime - this.manager.loopEndOffset) {
201+
this.audio.currentTime = startTime + Math.max(0, currentTime - endTime);
202+
currentTime = this.audio.currentTime;
203+
}
204+
else if (currentTime < startTime) {
205+
this.audio.currentTime += startTime;
206+
currentTime = this.audio.currentTime;
207+
}
208+
if (currentTime < this.previousTime) {
209+
// TODO rename to looped and add loop for changing loop value
210+
this.emit('loop', this);
211+
}
202212
}
203213
else if (currentTime >= endTime) {
204214
this.reset();
205215
this.stopAndReleaseAudioTag();
206216
this.emit('ended', this);
207217
return;
208218
}
209-
else if (currentTime < startTime) {
210-
this.audio.currentTime += startTime;
211-
currentTime = this.audio.currentTime;
212-
}
213-
if (this.currentConfig.loop && currentTime < this.previousTime) {
214-
// TODO rename to looped and add loop for changing loop value
215-
this.emit('loop', this);
216-
}
217219
this.previousTime = currentTime;
218220
}
219221
},

0 commit comments

Comments
 (0)