Audio object method play() in Javascript
The audio object method play() used to start playing the current audio. It can be used to play audio again if audio is paused or if auto play is off on page load.
Syntax
 1 <audio>.play()
audio : A audio element object to start playing video by using play() method
Audio method play()
 1 <html>
 2 <style>
 3   .container {
 4     margin: 10px 0;
 5   }  
 6 </style>
 7 <body>
 8 	<h1>The Audio Object</h1>
 9 	<h2>Example</h2>
 10 	
 11 	<div>
 12 	  <audio id="audio" controls >
 13 	    <source id="source" src="audio.mp3" type="audio/mpeg">
 14 	    Your browser does not support the audio tag.
 15 	  </audio>
 16 	</div>
 17 	<p>
 18 	  <button onclick="access(true)">Play</button>
 19 	  <button onclick="access(false)">Pause</button>
 20 	</p>
 21 	<p id="result"></p>
 22 	
 23 	<script>
 24 	function access(value) {	  
 25 	  const audio = document.getElementById("audio")
 26 	  value ? audio.play() : audio.pause();
 27 	  const str = `audio ${value ? 'Audio playing !' : 'Audio paused !' }`;
 28 	  document.getElementById("result").innerHTML = str;
 29 	}
 30 	</script>
 31 </body>
 32 </html>
Audio method play()
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us