How to put a sound on js?? Pls help me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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,.. 🙄

18th May 2019, 3:56 PM
Yanjka
Yanjka - avatar
2 Answers
+ 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();
18th May 2019, 4:06 PM
Airree
Airree - avatar