Hello. I really need your help.

On the site I want to place a button that plays music. Press - play music. The second press - pause. The third is a continuation from the place where the pause was pressed.

Here is the code:

<script> function StartOrStop(audioFile) { var audie = document.getElementById("myAudio"); if (!audie.src || audie.src !== audioFile) audie.src = audioFile; console.log(audie.paused); if (audie.paused == false) { console.log('pause'); audie.pause(); } else { console.log('play'); audie.play(); } } </script> <button class="hello" onclick="StartOrStop('audio5.mp3')">Послушайте наше аудио!</button> <audio id="myAudio"></audio> 

The problem is that this code works properly only for the .oga format. If you use .mp3, then when you press the button again, the music simply plays again.

Many thanks for the replies!

    1 answer 1

    You can try to solve the problem by saving / setting the currentTime property: HTML Audio / Video DOM currentTime Property .