I want to play a sound in my application whenever a tab is available in browser irrespective focus. I am using HTML 5 audio tag to play the sound. But chrome and safari defer the audio playing until the user navigate or focus to the tab. The entire audio request to play sound is played at a time of tab focus. It bees too noisy when you hear lot of sound playing at a time. Is it possible to play a sound from unfocused tab without browser defer nature? Suggest me any alternative solution available for handling this situation. Thanks in advance.
I want to play a sound in my application whenever a tab is available in browser irrespective focus. I am using HTML 5 audio tag to play the sound. But chrome and safari defer the audio playing until the user navigate or focus to the tab. The entire audio request to play sound is played at a time of tab focus. It bees too noisy when you hear lot of sound playing at a time. Is it possible to play a sound from unfocused tab without browser defer nature? Suggest me any alternative solution available for handling this situation. Thanks in advance.
Share Improve this question asked Apr 12, 2016 at 2:20 RajanRajan 4262 gold badges7 silver badges28 bronze badges 1- So all you want is a audio tag to play even if you're on another tab? – zer00ne Commented Apr 23, 2016 at 0:10
1 Answer
Reset to default 7This is the expected behavior since Chrome 46. To optimize browser performance and to conserve power, Google has disabled the auto-play on the background tabs. However starting from Chrome 47, there is a way for a person to override it by enabling the Chrome flag
chrome://flags/#disable-gesture-requirement-for-media-playback
UPDATE: Chrome flag is no longer available since Chrome 60 (thank you @gordie)
There is no workaround that would allow sound to play in the 'background' tab. The solution is to not play any sounds until the page is focused. For that you can either use the window.onfocus
event handler or, preferably, the Visibility API (more info).