0

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.

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by Thropian
0

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.