At the beginning of my page, there is a song that plays automatically. When it ends, it should go to the next song, however I do not understand why it is not doing so, if in my conditional I place it, when the song ends, the next one starts. The alert within my function does not appear.
The code is as follows:
currentTrack = 0
beats = ['eminem.mp3', 'icecube.mp3', 'lilwayne.mp3', 'nas.mp3', 'still.mp3', 'today.mp3']
beat = document.getElementById('beat')
if(beat.ended == true){
function reproducir(){
alert("estoy dentro de la funcion")
nextTrack = beats[currectTrack++]
beat.setAttribute('src', nextTrack)
beat.play
})
}
<audio src="../estudio/beats/eminem.mp3" autoplay controls id="beat"></audio>
<button onclick="reproducir()">iniciar</button>
<button onclick="detener()">detener</button>
<div id="seccion"></div>
Why is that happening? How can I solve it?