1
I want the audio to repeat from the beginning every time the button is pressed. Instead it only repeats after the audio has finished. (NOTE: I am using JSX)
Javascript
playShot() {
var audio = document.getElementById('shot');
audio.play();
}
HTML
<a onClick={() => this.playShot()} style={{zIndex: 5}} id="gat"><img src={gate2}/></a>
It worked! Thanks friend, for the solution and also for the suggestion of Let. I am new in programming and have a lot to learn.
– JPTS
You say it’s optional if the
play()
is already running. Is there any way to verify this? Type the objectáudio
launches some event that ended the execution?– Jefferson Quesado
@Jeffersonquesado is possible to verify using the property
audio.paused
and at the end of the audio run, the player will launch an event foraudio.onended()
– Valdeir Psr