0
How to put a sound on js?? Pls help me
And where can i find random short sounds like dog bark or water drop etc,.. 🙄
2 Réponses
+ 4
You have to make the audio element like this:
<audio id = "audio">
<source src = "something.mp3"
type = "audio/mpeg">
</audio>
It is also probably a good idea to make it invisible:
#audio {
visibility: hidden;
/*OR*/
display: none
}
You can create the audio object like this (make sure the variable is declared after the paged loads (like placing it in window.onload = function() {//code})):
let a = document.getElementById("audio");
You can play/pause it like this:
a.play();
a.pause();