Skip to content

Commit 9a9f50f

Browse files
committed
Instantly fire end event if sound is seeked past its duration
Fixes #963
1 parent e0343aa commit 9a9f50f

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/howler.core.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,12 @@
723723
sound._stop = (self._sprite[sprite][0] + self._sprite[sprite][1]) / 1000;
724724
sound._loop = !!(sound._loop || self._sprite[sprite][2]);
725725

726+
// End the sound instantly if seek is at the end.
727+
if (sound._seek >= sound._stop) {
728+
self._ended(sound);
729+
return;
730+
}
731+
726732
// Begin the actual playback.
727733
var node = sound._node;
728734
if (self._webAudio) {
@@ -1470,28 +1476,33 @@
14701476
sound._ended = false;
14711477
self._clearTimer(id);
14721478

1473-
// Restart the playback if the sound was playing.
1474-
if (playing) {
1475-
self.play(id, true);
1476-
}
1477-
14781479
// Update the seek position for HTML5 Audio.
14791480
if (!self._webAudio && sound._node) {
14801481
sound._node.currentTime = seek;
14811482
}
14821483

1484+
// Seek and emit when ready.
1485+
var seekAndEmit = function() {
1486+
self._emit('seek', id);
1487+
1488+
// Restart the playback if the sound was playing.
1489+
if (playing) {
1490+
self.play(id, true);
1491+
}
1492+
};
1493+
14831494
// Wait for the play lock to be unset before emitting (HTML5 Audio).
14841495
if (playing && !self._webAudio) {
14851496
var emitSeek = function() {
14861497
if (!self._playLock) {
1487-
self._emit('seek', id);
1498+
seekAndEmit();
14881499
} else {
14891500
setTimeout(emitSeek, 0);
14901501
}
14911502
};
14921503
setTimeout(emitSeek, 0);
14931504
} else {
1494-
self._emit('seek', id);
1505+
seekAndEmit();
14951506
}
14961507
} else {
14971508
if (self._webAudio) {

0 commit comments

Comments
 (0)