0

Audio AutoPlay

I'm just getting into HTML, and finally got to the HTML5 part of the course and I've finally run into a problem I couldn't get the solution from the comments. I am simply trying to make the song autoplay when the page is opened. At first I added the audio to the website using <audio src="audio.mp3" controls> </audio> Which it ran fine and I was able to use it without a hitch. So I decided to use a different way as stated in the lesson <source src="audio.mp3" type="audio/mpeg"> Audio element not supported by your browser. </audio> For some reason however, this way via source src does not work? It displays on the webpage as an audio file is there, however the time listed for the song is stated 0:00/0:00 Weirdly enough I decided to just keep moving on with <audio src=> and see if this is just a better way to do it, but by adding autoplay to <audio src="audio.mp3" controls autoplay> I was not able to get the page to play it automatically. As well as I have tried this with source as well but it still lists the song as 0:00. Is there something I am doing wrong here? At the moment I don't believe I would actually use autoplay for anything on something I would create in the future, but I just really would like to understand the fundamentals of getting it to work so that I can say I understand it. Thank you in advance to anybody that offers their advice!

28th Dec 2019, 7:14 AM
Justin Thomas
Justin Thomas - avatar
5 Respostas
0
I'm just curious as to why it does not work
28th Dec 2019, 2:05 PM
Justin Thomas
Justin Thomas - avatar
0
Justin Thomas I'd need to see the exact markup you used to give any insight. Also, which browsers have you tested this on?
28th Dec 2019, 4:35 PM
David Carroll
David Carroll - avatar
0
My code would be as follows: <html> <head> <title>My Webpage</title> </head> <body> <audio src="audio.mp3" controls autoplay> Audio element not supported by your browser. </audio> </body> </html> Which does play music, but it does not autoplay. As well as the source function code is as follows <html> <head> <title>My Webpage</title> </head> <body> <audio controls> <source src="audio.mp3" type="audio/mp3"> </audio> </body> </html> Using this method leaves the audio file in the browser as 0:00/0:00 and does not have any music to play. Also I have only tested Firefox, I can try other browsers. But does Firefox have a history of limitations like this?
28th Dec 2019, 9:27 PM
Justin Thomas
Justin Thomas - avatar