Play audio again before first playthrough finishes

Tell us what’s happening:

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.

Challenge: Build a Drum Machine

Link to the challenge:

Hello there,

This is usually a simple fix. I suggest you read over the audio element events. The answer lies there.

Hope this helps

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.currentTime = 0

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.