generate pause between songs

0

hi can you tell me how I can do so that when a song ends, the pause starts, each time a song ends, the pause is paused before following the next song

<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>
<script type="text/javascript">

currentTrack = 0

beats = ['still.mp3', 'today.mp3']
pausa = "../estudio/beats/pausa.mp3"

beat = document.getElementById('beat')

beat.addEventListener('ended', function(){

nextTrack = beats[currentTrack++]
if(nextTrack){beat.setAttribute('src', pausa)}
beat.setAttribute('src', "../estudio/beats/"+nextTrack)
beat.play()
if(currentTrack == beats.length){currentTrack = 0}

})

</script>
    
asked by steven 14.04.2017 в 21:25
source

1 answer

3

Listening to the Event onended , but when this occurs, call setTimeout to execute the wait, and then assign the new audio to play

<audio src="audio.mp3" autoplay controls id="beat"></audio>

beats = ['still.mp3', 'today.mp3'];
var audio = document.getElementById('beat');
audio.onended = function() {
    setTimeout(function(){
         audio.setAttribute('src',  beats[0]);/* primera canción*/
    }, 6000);/* 6 Segundos de Espera*/
    audio.setAttribute('src', 'pause.mp3');/* El audio pause es > 6 segundos*/
};
    
answered by 14.04.2017 / 21:44
source