audio player play/pause and stop

function play(idPlayer, control) {
    var player = document.querySelector('#' + idPlayer); 
    if (player.paused){
        player.play();
        control.textContent="⏸️"; // pause
    } else {
        player.pause();
        control.textContent="▶️"; // play
    };
}

function stop(idPlayer) {
    var player = document.querySelector('#' + idPlayer);
    player.currentTime = 0;
    player.pause();
}

document.addEventListener('play', function(e){  
    var audios = document.getElementsByTagName('audio');  
    for(var i = 0, len = audios.length; i < len;i++){  
        if(audios[i] != e.target){  
            audios[i].pause();  
        }  
    }  
}, true);
<audio id="audioPlayer1" preload="none">
<source src="www.dieuestamour.fr/Files/Audio/Chaque_jour_les_ecritures/essais.mp3" type="audio/mpeg">
Désolé, votre navigateur ne supporte pas HTML5 audio.
</audio>
<button onclick="play('audioPlayer1', this)" style="cursor:pointer;" alt="Bouton play/pause audio" title="Cliquez pour lecture / pause&#10;L'audio commence par la lecture de la bible.">&#x25B6;&#xFE0F;</button>
<button onclick="stop('audioPlayer1')" style="cursor:pointer;" alt="Bouton arrêt audio" title="Cliquez pour arrêter">&#x23F9;&#xFE0F;</button>

put the play/pause button to play when there is the stop button and the end of the audio.

I can’t put everything down because I don’t remember it but nothing worked.

<script>
function play(idPlayer, control) {
    var player = document.querySelector('#' + idPlayer); 
    if (player.paused){
        player.play();
        control.textContent="⏸️"; // pause
    } else {
        player.pause();
        control.textContent="▶️"; // play
    };
}

function stop(idPlayer) {
    var player = document.querySelector('#' + idPlayer);
    player.currentTime = 0;
    player.pause();
}

document.addEventListener('play', function(e){  
    var audios = document.getElementsByTagName('audio');  
    for(var i = 0, len = audios.length; i < len;i++){  
        if(audios[i] != e.target){  
            audios[i].pause();  
        }  
    }  
}, true);
</script>
<audio id="audioPlayer1" preload="none">
    <source src="www.dieuestamour.fr/Files/Audio/Chaque_jour_les_ecritures/essais.mp3" type="audio/mpeg">
    Désolé, votre navigateur ne supporte pas HTML5 audio.
</audio>
<button onclick="play('audioPlayer1', this)" style="cursor:pointer;" alt="Bouton play/pause audio" title="Cliquez pour lecture / pause&#10;L'audio commence par la lecture de la bible.">&#x25B6;&#xFE0F;</button>
<button onclick="stop('audioPlayer1')" style="cursor:pointer;" alt="Bouton arrêt audio" title="Cliquez pour arrêter">&#x23F9;&#xFE0F;</button>

Leave a Comment