I want to add sounds in JS. Can anyone help please? | Sololearn: Learn to code for FREE!

+7

I want to add sounds in JS. Can anyone help please?

I want to add sounds in my code, but I don't know how to do it. Can anyone help please? I want to add sounds from my recordings which I have recorded in my mobile. Thanks!👍

6/27/2018 10:22:03 AM

Rahul Hemdev

6 Answers

New Answer

+6

var audio = new Audio(source); audio.loop = false; audio.play();

+6

Ok. Thanks!

+6

https://code.sololearn.com/W8Yp74D9f63n/?ref=app Why isn't the music playing? Do you know the reason?

+5

url = source of audio ?

+5

Your source is faulty. You need to specify the url http://hosting.com/audio.mp3 Here try this https://raw.githubusercontent.com/V-Play/FlappyBird/master/assets/audio/sfx_point.wav var url = “https://raw.githubusercontent.com/V-Play/FlappyBird/master/assets/audio/sfx_point.wav”; var audio = new Audio(url); audio.loop = false; audio.play();

+4