+20

How to add a background music in html

Simply wanna add a background music so that it follows a loop and it is hidden to the Page and use an auto play option..

3/18/2019 7:05:34 AM

bhomic

25 Answers

New Answer

+19

bhomic kaushik Autoplay is not supported. You should use js : Add id "a" to <audio> in html section: <audio id="a" ... > // in js section : window.addEventListener("mouseover",play); window.addEventListener("click",play); function play() { document.getElementById("a").play(); }

+17

bhomic kaushik hi, pls refer to this video: https://youtu.be/y7jOwzozumU

+9

bhomic kaushik rename "Ben 10 opening HD" to "Ben 10 opening HD.mp3" to make it an audio file

+9

bhomic kaushik use <audio controls autoplay>

+9

https://www.w3schools.com/html/html5_audio.asp

+9

you can visit this for more info about autoplay policy https://developers.google.com/web/updates/2017/09/autoplay-policy-changes

+7

VEDANG well once again thanks.. I tried but didn't worked.....

+6

thanks Zhenis Otarbay

+6

Rock Leone for example?? Plz tell!.. It will be really helpful...if its the cause ... I have tried YouTube repeater but it doesn't works...what i think that sololearn has denied this feature to improve security ...

+6

VEDANG thanks again... But now its not so important as i have learnt click play from you...... Thanks for that...

+5

What's wrong in the below code ??? See the audio tag ... I know its wrong . But how to make the dropbox link work for audio.... Edit: Solved : because of answers given https://code.sololearn.com/W0WuML8AyNA6/?ref=app

+5

Ok i will try and thanks VEDANG for the reply

+5

The song running problem is solved but can anyone tell me about : how to add an auto play option to the music in html

+5

VEDANG thank you very much for the answer

+5

Fahim Ahmad thanks ... Loop is working very cool and the option of display:none; is great fir hiding the music window.. but i think that autoplay option has been removed...... thanks a lot...

+5

VEDANG yeah it worked.... Thanks for teaching me : how to make a function to play the music when the screen is clicked anywhere.... Thanks you very much much...

+4

Thanks Rock Leone. for the reply but i was trying to use it in sololearn... Now i understood that i can't.....

+3

<audio src="Lose Yourself.mp3" autoplay> This is a background music </audio> make sure the autoplay audio option is enabled in your corresponding browser.............

+3

yup you can..... but you have to find a website which stream online songs.......

+3

recent updates have restricted the you tube plug in via SoloLearn playground