Skip to content

Commit a6ec0af

Browse files
Using loopEndOffset when checking if sound looped
1 parent 042f778 commit a6ec0af

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

src/sound/html5/HTML5AudioSound.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,15 @@ var HTML5AudioSound = new Class({
186186
var startTime = this.currentMarker ? this.currentMarker.start : 0;
187187
var endTime = startTime + this.duration;
188188
var currentTime = this.audio.currentTime;
189-
if (currentTime >= endTime) {
190-
if (this.currentConfig.loop) {
191-
this.audio.currentTime = startTime + (currentTime - endTime);
192-
currentTime = this.audio.currentTime;
193-
}
194-
else {
195-
this.reset();
196-
this.stopAndReleaseAudioTag();
197-
this.events.dispatch(new SoundEvent(this, 'SOUND_ENDED'));
198-
return;
199-
}
189+
if (this.currentConfig.loop && currentTime >= endTime - this.manager.loopEndOffset) {
190+
this.audio.currentTime = startTime + Math.max(0, currentTime - endTime);
191+
currentTime = this.audio.currentTime;
192+
}
193+
else if (currentTime >= endTime) {
194+
this.reset();
195+
this.stopAndReleaseAudioTag();
196+
this.events.dispatch(new SoundEvent(this, 'SOUND_ENDED'));
197+
return;
200198
}
201199
else if (currentTime < startTime) {
202200
this.audio.currentTime += startTime;

0 commit comments

Comments
 (0)