admin 管理员组文章数量: 1086019
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).
本文标签:
版权声明:本文标题:javascript - HTML5 audio tag not playing sound for the very first of unfocused tab in chrome and safari? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744077982a2529704.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论