I’m working on the Build a Drum Machine project.
My issue is that it wont play the audio clip again until the first instance ends.
I can play two different sounds over each other, but I’m unable to play the same sound over itself like in the example project. What modification do I need to make for it to work like that? Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36.
That link is for audio elements. I’m using an audio object with no <audio> nodes. Can those elements be applied to the object? Or will I have to use the <audio> nodes in my code instead?
Edit: Ok, so I see the actual way the example works is that it stops the audio and replays it from the beginning if it hasn’t finished yet. I was misunderstanding thinking it was playing the same instance of the audio over itself…
I assume I have to get the current play state of the audio and stop it before starting the new instance… That sound somewhat right?
Edit #2: I found a solution… does this seem ok? Was there a better solution?
if (audio.paused) {
audio.play();
}else{
audio.currentTime = 0
}