I am not really experienced with the use of javascript so this question could be a bit silly. I'm currently trying to develope a soundboard. Everything is working fine except one thing, i want to stop a sound when another button is clicked and i really don't know how i can do this.
That's an example for what i want to do: I click button 1, the sound is played and while the sound is still playing I click button 2 and the sound of button 1 stops while the sound of button 2 starts to play.(And so on with every button)
Html code:
function EvalSound(soundobj) {
var thissound = document.getElementById(soundobj);
thissound.play();
}
audio {
visibility: hidden;
}
<audio class="audio" id="a" src="" controls preload="auto" autobuffer></audio>
<audio class="audio" id="b" src="b.wav" controls preload="auto" autobuffer></audio>
<audio class="audio" id="c" src="c.mp3" controls preload="auto" autobuffer></audio>
<input type="button" class="button" value="Button 1" onClick="EvalSound('a')">
<input type="button" class="button" value="Button 2" onClick="EvalSound('b')">
<input type="button" class="button" value="Button 3" onClick="EvalSound('c')">