YouTube Icon

How to Play Audio After Few Seconds or Delay in JavaScript

How to Play Audio After Few Seconds or Delay in JavaScript

In this instructional exercise, I will demonstrate to you how effortlessly you can play sound following couple of moments or some time defer effectively utilizing JavaScript. 

Here we going to make a HTML document with a sound tag and a sound src record. At that point we will stack it in our program. From there on, We will make a JavaScript capacity to play that sound with some deferral so it plays after a specific timeframe. 

Also Read:- How to Create Calculator Using HTML, CSS and JavaScript

To see the video instructional exercise play this video 

Play sound following couple of moments in JavaScript 

In this past post How to Play Audio After The Page Loads in HTML With JavaScript I have portrayed completely. 

You can tap on the above connection to figure out how to play sound after page stack utilizing JavaScript. 

<script type="text/javascript"> 



}, 8000) 


You can see, here I have utilized setTimeout capacity to accomplish the postponement. 



}, 8000);

Also Read:- How to Create Multiplication Table Using JavaScript

This is the primary capacity to play sound following 8 seconds. 


/your code goes here 

}, enter defer time in miliseconds) 

You may likewise intrigued by, 

Alarm Before Leaving A Web Page Using JavaScript jQuery 

Base Sticky Music Player Source Code in JavaScript and CSS 

To check if your capacity is working or not you can utilize comfort log. 

console.log('your sound is begun a little while ago'); 

This line will include a reassure message when the sound begins playing. 

Also Read:- How to Write Java Program to Print Armstrong numbers from 0 to 999

You can test the beneath code 

<!DOCTYPE html> 



<title>My Audio</title> 



<audio src="mysong.mp3" id="my_audio" loop="loop"></audio> 

<script type="text/javascript"> 



console.log('your sound is begun a little while ago'); 

}, 8000) 




Simply put your sound way in the src characteristic. circle will play the sound document over and over.

Also Read:- Top Five Programming Languages For Jobs and for the Future

Author Biography.


CrowdforThink is the leading Indian media platform, known for its end-to-end coverage of the Indian startups through news, reports, technology and inspiring stories of startup founders, entrepreneurs, investors, influencers and analysis of the startup eco-system, mobile app developers and more dedicated to promote the startup ecosystem.

Join Our Newsletter.

Subscribe to CrowdforThink newsletter to get daily update directly deliver into your inbox.

CrowdforGeeks is where lifelong learners come to learn the skills they need, to land the jobs they want, to build the lives they deserve.


CrowdforThink is a leading Indian media and information platform, known for its end-to-end coverage of the Indian startup ecosystem.


Our mission is "Har Koi Dekhe Video, Har Ghar Dekhe Video, Ghar Ghar Dekhe Video" so we Provide videos related to Tutorials, Travel, Technology, Wedding, Cooking, Dance, Festivals, Celebration.

Apna Video Wala

News & Blogs


An In-Depth Guide On Choosing Best Frontend Fra...

Since the outbreak of COVID-19, business operations have been moved online to make ends meet....


What is the Difference Between =, ==, and === i...

What is = in JS?  Equivalent to (=) is a task administrator, which sets the variable on t...


JavaScript Mobile Frameworks worth considering ...

When it comes to startups entering the business arena, they have very tough competition. This is ...

Top Authors

Lamia Rochdi is the Marketing Manager at Bell Flavors & Fragrances EMEA. A successful family-...

Lamia Rochdi

I’m Mertin Wilson a technician in a camera company and certified expert of different P...

Mertin Wilson

Zakariya has recently joined the PakWheels team as a Content Marketing Executive, shortly after g...

Zakariya Usman

Pankaj Singh is a Senior Digital Marketing Consultant with more than 2 years of experience in SEO...

Pankaj Singh

Our Client Says

WhatsApp Chat with Our Support Team