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?

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

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")
soundEmbed.addEventListener("ended",RandomSong)

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

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, networking, learning, and sharing knowledge.