An application is playing an audio clip with the HTMLAudioElement nested in some JavaScript like below,
var s = new Audio('/sounds/s.wav');
s.play();
HTMLAudioElement docs: https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement
The problem is that the clip needs to play every time a user takes an action. But if the previous audio clip is still playing then the next clip will not play (be delayed or skip completely).
So is there a way to cutoff an audio clip, mid way while it's playing?
Something like s.stop()
?
UPDATE
Maybe this is still a duplicate question...
There are multiple audio clips for different actions so if implemented sound.pause();
and sound.currentTime = 0;
from referenced duplicate question, it might look something like this, which could be run before each clip.
function stopSounds() {
sound1.pause();
sound1.currentTime = 0;
sound2.pause();
sound2.currentTime = 0;
sound3.pause();
sound3.currentTime = 0;
sound4.pause();
sound4.currentTime = 0;
sound5.pause();
sound5.currentTime = 0;
sound6.pause();
sound6.currentTime = 0;
sound7.pause();
sound7.currentTime = 0;
}