Audio play() Method in javascript

Definition and Usage

The play() method starts playing the current audio.

Tip: The audio() method is often used together with the pause() method.

Tip: Use the controls property to display audio controls (like play, pause, seeking, volume, etc, attached on the audio).



An audio player with play and pause buttons:

<!DOCTYPE html>

<audio id="myAudio">
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
  Your browser does not support the audio element.

<p>Click the buttons to play or pause the audio.</p>

<button onclick="playAudio()" type="button">Play Audio</button>
<button onclick="pauseAudio()" type="button">Pause Audio</button> 

var x = document.getElementById("myAudio"); 

function playAudio() {; 

function pauseAudio() { 


Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button