Autoplay sound in chrome background tab Autoplay sound in chrome background tab google-chrome google-chrome

Autoplay sound in chrome background tab


The solution that worked for me was to play a small blank sound (0.1 second is enough) once the page is loaded. After that even if you switch to another tab, the tab in the background will still be able to play the sound on some external or internal event.


Example 1

Here is an example that creates a div and uses HTML5 <audio> tag with a fallback to <embed> that plays an audio file 3 seconds after clicking the button.

To test it, run the sample and click the button, then change tabs and count 3 seconds. You should see the speaker icon on this tab and hear the coin drop sound after 3 seconds even though this tab is not the current tab.

function playCoinDrop() {  soundDiv = document.createElement("div");  soundDiv.innerHTML = '<audio autoplay="autoplay"><source src="http://themushroomkingdom.net/sounds/wav/smw/smw_coin.wav" type="audio/wav" /><embed hidden="true" autostart="true" loop="false" src="http://themushroomkingdom.net/sounds/wav/smw/smw_coin.wav" /></audio>';}
<button onclick="setTimeout(playCoinDrop, 3000)">play sound</button>