Skip to content

Commit

Permalink
Instantly fire end event if sound is seeked past its duration
Browse files Browse the repository at this point in the history
  • Loading branch information
goldfire committed Jul 12, 2018
1 parent 174a4ac commit 7fdffa4
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/howler.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,12 @@
sound._stop = (self._sprite[sprite][0] + self._sprite[sprite][1]) / 1000;
sound._loop = !!(sound._loop || self._sprite[sprite][2]);

// End the sound instantly if seek is at the end.
if (sound._seek >= sound._stop) {
self._ended(sound);
return;
}

// Begin the actual playback.
var node = sound._node;
if (self._webAudio) {
Expand Down Expand Up @@ -1470,28 +1476,33 @@
sound._ended = false;
self._clearTimer(id);

// Restart the playback if the sound was playing.
if (playing) {
self.play(id, true);
}

// Update the seek position for HTML5 Audio.
if (!self._webAudio && sound._node) {
sound._node.currentTime = seek;
}

// Seek and emit when ready.
var seekAndEmit = function() {
self._emit('seek', id);

// Restart the playback if the sound was playing.
if (playing) {
self.play(id, true);
}
};

// Wait for the play lock to be unset before emitting (HTML5 Audio).
if (playing && !self._webAudio) {
var emitSeek = function() {
if (!self._playLock) {
self._emit('seek', id);
seekAndEmit();
} else {
setTimeout(emitSeek, 0);
}
};
setTimeout(emitSeek, 0);
} else {
self._emit('seek', id);
seekAndEmit();
}
} else {
if (self._webAudio) {
Expand Down

0 comments on commit 7fdffa4

Please sign in to comment.