I'm making a player where several music sounds and I want every x
minutes, apart from the player, to play a single music without touching any button, only when entering the page, and in those x
minutes the music sounds , right now just touching a button sounds, but I want it to sound in those x minutes, and then sound again every x minutes, that is I have to do a setInterval()
but I do not know where to place it, I attach my code so that it looks better:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
window.onload=function(){
// creamos el objeto audio
var audioElement = document.createElement('audio');
// indicamos el archivo de audio a cargar
audioElement.setAttribute('src', 'mimusica.mp3');
document.getElementById("play").addEventListener("click", function() {
// Si deseamos que inicie siempre desde el principio
//audioElement.currentTime = 0;
// iniciamos el audio
audioElement.play();
});
document.getElementById("pause").addEventListener("click", function() {
// hacemos pausa
audioElement.pause();
});
};
</script>
</head>
<body>
<div>
<input type="button" value="Play" id="play">
<input type="button" value="Pause" id="pause">
</div>
</body>
</html>
I want it to sound automatically in x
minutes, and then repeat again in those x
minutes