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. 

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"> 

setTimeout(function(){ 

document.getElementById("id_here").play(); 

}, 8000) 

</script> 

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

setTimeout(function(){ 

document.getElementById("id_here").play(); 

}, 8000);

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

setTimeout(function(){ 

/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. 

You can test the beneath code 

<!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 sound is begun a little while ago'); 

}, 8000) 

</script> 

</body> 

</html> 

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



Author Biography.

CrowdforThink
CrowdforThink

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.

CrowdforJobs is an advanced hiring platform based on artificial intelligence, enabling recruiters to hire top talent effortlessly.

CrowdforJobs

CrowdforApps brings to you the well researched list of the most successful and finest App development companies, Web software developers.

CrowdforApps

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

CrowdforGeeks

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

CrowdforThink
CFT

News & Blogs

d7c8b3433a607583dc5bb1bf47f7041f.png

How to Generate a PDF with JavaScript

An extremely regular use case today is that of enabling your clients to download information from...

f95b8815ecdfedc8ef0d66ac816d5027.png

How to Create A Countdown Timer with Progress B...

In this instructional exercise, I am will demonstrate to you proper methodologies to make a comme...

f62dbc1a41f2267ac3920998ea272871.jpg

You Don’t Need Loops in JavaScript

1. To Loop Through All Elements and Get an new modified array Using loop: var names = ["Jack",...

Top Authors

Hey, I am Suraj - a full-time blogger and a social media expert currently working on the Growth H...

Suraj Kumar

With good communication and writing skiils, Astha Sharma is a full-time content writer working wi...

Astha Sharma

Overall 3+ years of experience as a Full Stack Developer with a demonstrated history of working i...

Lokesh Gupta

Aditya Sehgal is a recognised financial adviser, tech and gadget writer and blogger. Still he has...

Aditya Sehgal
CFT

Our Client Says

WhatsApp Chat with Our Support Team