Repeat audio every time button is clicked - Javascript and HTML

1

I want the audio to repeat every time the button is pressed. Instead, it only repeats after the audio finishes. (NOTE: I'm 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>
    
asked by anonymous 14.02.2018 / 00:41

1 answer

4

Change the currentTime property of the audio element.

playShot() {
    let audio = document.getElementById('shot');
    audio.currentTime = 0
    audio.play(); // É opcional caso o play já esteja em execução.
}
    
14.02.2018 / 01:03