Javascript DOM HTML Audio pause() Method

Introduction

An audio player with play and pause buttons:

Click the buttons to play or pause the audio.

View in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio">
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>//from   w w w.  j av a  2s.co m
<button onclick="playAudio()" type="button">Play Audio</button>
<button onclick="pauseAudio()" type="button">Pause Audio</button> 

<script>
var x = document.getElementById("myAudio"); 

function playAudio() { 
  x.play(); 
} 

function pauseAudio() { 
  x.pause(); 
} 
</script>

</body>
</html>

The pause() method can pause the currently playing audio.




PreviousNext

Related