1
I have this script, that when I click it plays the audio:
<!DOCTYPE html>
<html>
<div id="oi" onclick="reproduzir('audio01.mp3')">ME CLIQUE</div>
<audio id="audio">
<source src="" type="audio/mpeg">
Seu navegador não possui suporte ao elemento audio
</audio>
</html>
<script>
audio = document.getElementById('audio');
function reproduzir(urlMusica){
audio.src = urlMusica;
audio.play();
}
</script>
and wanted it to reproduce itself when I use the "onload" I have tried several ways, but not right. someone could give me a light?
You don’t need Js for this just set the tag
audio
the property self-play.– LeAndrade