Playing audio in HTML

HTML JavaScript

Assuming you are working with HTML5, you can embed the audio element.

<audio id="someId"> <source src="sounds/ding.wav" type="audio/wav"></source> Your browser does not support the audio element. </audio>

Then play the music based on the ID and . You have to use JavaScript getElementById('someId') as jQuery won't work.

var audio = document.getElementById('someId') // play audio.play() // pause audio.pause() // restart if (audio.paused) { audio.play() }else{ audio.pause() audio.currentTime = 0 }

Reference

audio element developer.mozilla.org

History Nov 22, 2017