Why doesn't background music work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
9th Feb 2020, 12:52 PM
KyteZ
KyteZ - avatar
13 Answers
+ 2
i can think of a work around, dont know if itll work. go to js inside window onload listener. create another load listener for <audio> then play()
9th Feb 2020, 3:00 PM
Taste
Taste - avatar
+ 1
close the audio tag </audio>
9th Feb 2020, 2:58 PM
Taste
Taste - avatar
+ 1
You can only play an audio file when a user allows it to play, Which means that you have to add eventListener like "click" to trigger the play() method Do it like this.. In html <div id="song"> play song</div> Do some styling in css.. In js Var song = document.getElementById("song") Song.addEventListener("click", function(){ Your_audio_name.play(); });
10th Feb 2020, 2:34 PM
ugochukwu Joseph
ugochukwu Joseph - avatar
+ 1
You need to put controls for audio, like this: <audio controls src="" autoplay> My advice: don't put autoplay attribute, it's very annoying from the users' point of view. Cool code, you are doing great!
11th Feb 2020, 6:20 AM
Elena Shatalova
Elena Shatalova - avatar
0
try audio with autoplay <audio autoplay src=""> i cant load the url, tried it in browser same result. idk maybe its just my internet
9th Feb 2020, 1:06 PM
Taste
Taste - avatar
0
it don't help
9th Feb 2020, 2:41 PM
KyteZ
KyteZ - avatar
0
check the url, is it really working ? i tried it before its not sending anything
9th Feb 2020, 2:42 PM
Taste
Taste - avatar
0
url works
9th Feb 2020, 2:45 PM
KyteZ
KyteZ - avatar
0
and now after I entered <audio> my blocks disappeared
9th Feb 2020, 2:46 PM
KyteZ
KyteZ - avatar
9th Feb 2020, 3:14 PM
Taste
Taste - avatar
0
thanks
9th Feb 2020, 3:15 PM
KyteZ
KyteZ - avatar
11th Feb 2020, 1:27 AM
Duncan
Duncan - avatar