(HTML5) I can't put in an audio autoplay for my website that i code in sublime 3, can someone please help ? 😊 | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

(HTML5) I can't put in an audio autoplay for my website that i code in sublime 3, can someone please help ? 😊

<!DOCTYPE html> <html> <head> <meta chartset="UTF-8"> <title>audio</title> </head> <body> <audio> <iframe src="file:///C:/Users/User/Desktop/Siteweb_JuliaMoi/accueil/audio.html" autoplay/> </audio> </body> </html> code isn't working

1st Mar 2020, 8:11 AM
Julia Melina Moi
Julia Melina Moi - avatar
7 Antworten
+ 2
add <script>onload = () => { document.addEventListener("click", () =>{ document.querySelector("audio").play() })} </script> and click the screen once.
1st Mar 2020, 10:01 AM
Gordon
Gordon - avatar
+ 2
its a policy that audio need user interaction to play. so autoplay is no longer possible atm. https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
1st Mar 2020, 8:24 AM
Taste
Taste - avatar
0
Please clarify your questions. Are you having problem of 1. Cannot add audio to webpage? 2. Cannot set the added audio to autoplay? 3. The audio works on localfile but not after you upload to a web host?
1st Mar 2020, 8:19 AM
Gordon
Gordon - avatar
0
I can't add the audio to the web page. I'm not sure whether i'm not coding right or if the file in mp3 isn't readable
1st Mar 2020, 8:22 AM
Julia Melina Moi
Julia Melina Moi - avatar
0
If you are doing it locally. There is a path issue. For file in the same root directory, you can use relative path. Let me create a video for you, just a minute.
1st Mar 2020, 8:24 AM
Gordon
Gordon - avatar
0
Thank you but it's still not working, here is my code: <!DOCTYPE html> <html> <head> <meta chartset="UTF-8"> <title>audio</title> </head> <body> <audio> <source src="audio.mp3" autoplay> </audio> </body> </html>
1st Mar 2020, 8:36 AM
Julia Melina Moi
Julia Melina Moi - avatar