I'm using HTML <embed> to play music in the background on a site, and I have a list of songs I'd like it to play. Is there some way to detect the end of the song and start the next?

soundEmbed = document.createElement("embed")
soundEmbed.setAttribute("src", "Music/"+Song)
soundEmbed.setAttribute("hidden", true)
soundEmbed.setAttribute("autostart", true)

This allows me to change songs (Bound to a button press) but I'd like it to run automatically. Any help would be appreciated.

Recommended Answers

All 2 Replies

Thanks Ryan, that was rather informative, though quite a bit more digging through than I expected. Over all I had to switch from using <embed> to using <audio> to get it to work.

soundEmbed = document.createElement("audio")

function RandomSong(){
Song = SongList[Math.random()*SongList.length]
soundEmbed.setAttribute("src", "Music/"+Song+".mp3")

Thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.