How can I put background music | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

How can I put background music

I want to listen to music without the need to press a button or an item https://code.sololearn.com/WfdJ33wTlust/?ref=app

22nd Apr 2020, 5:49 AM
Cmurio
Cmurio - avatar
3 Answers
+ 2
Autoplay is not possible due to modern browsers policies (similar to micro and cam). In iframes is more restrictive. but is always possible control using HTMLMediaElement DOM interface https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide
18th Aug 2021, 11:56 PM
David Ordás
David Ordás - avatar
+ 1
Actually using JavaScript like this must be worked: window.onload = function(){ audio.play() } But Console not let the script playing an audio without user Gesture
23rd Apr 2020, 7:40 AM
Farino
0
u can use <audio> if possible
22nd Apr 2020, 11:56 AM
Param Dudhe
Param Dudhe - avatar