How to Play Audio in Browser After Few Seconds Delay Using Settimeout() Method in Javascript Full Project For Beginners

 

Welcome folks today in this blog post we will be playing audio in browser after few seconds delay using settimeout() method in javascript. All the full source code of the application is given below.

 

 

 

Get Started

 

 

 

In order to get started you need to make an index.html file and copy paste the following code

See also  Build a Node.js YAML to JSON Converter Using yaml-to-json Library Using TypeScript Full Project For Beginners

 

 

index.html

 

 

 

<!DOCTYPE html>
<html>
<head>
  <title>My Audio</title>

</head>
<body>
  <audio src="mysong.mp3" id="my_audio" loop="loop"></audio>
  <script type="text/javascript">
    setTimeout(function(){
      document.getElementById("my_audio").play();
      console.log('your audio is started just now');
    }, 8000)
  </script>
</body>
</html>

Leave a Reply