How to add background-music in html? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to add background-music in html?

I tried using embed tag and bgsource tag it won't work.tell me your opinion through a example so that I would understand it properly?

12th Jul 2020, 10:17 AM
shubham kumar
shubham kumar - avatar
8 Answers
+ 3
Create a variable in javascript using new Audio() like this song = new Audio(); song.src="https://dl.dropbox.com/s/9thwwlf5qcl7k8s/Alan%20Walker%20-%20Faded.mp3?raw=0"; here i have used faded song Then in html section use this in body tag <body onclick="song.play()"> So when someone clicks any where in output song starts playing due to onclick event attribute.
12th Jul 2020, 10:23 AM
Varun N
Varun N - avatar
+ 3
Click the screen and the audio will be played https://code.sololearn.com/WfCR2cDMdj94/?ref=app
12th Jul 2020, 1:47 PM
Nilesh
+ 2
https://code.sololearn.com/WqlJtZNss9UW/?ref=app Here is my code that may help you to insert a background music.
12th Jul 2020, 10:34 AM
Akshay Panwar
Akshay Panwar - avatar
+ 1
Thank you bro(Akshay Panwar) for help.
12th Jul 2020, 11:00 AM
shubham kumar
shubham kumar - avatar
12th Jul 2020, 10:59 AM
shubham kumar
shubham kumar - avatar
0
Your most welcome shubham kumar
12th Jul 2020, 11:02 AM
Akshay Panwar
Akshay Panwar - avatar
12th Jul 2020, 1:08 PM
shubham kumar
shubham kumar - avatar
0
https://code.sololearn.com/WplL4058t0hT/?ref=app
18th Jul 2020, 4:38 PM
shubham kumar
shubham kumar - avatar