JavaScript – how to disable audio playback in Android chrome when the process is backgrounded?

How to programmatically disable songs playing in the background of chrome Android process?

The following is a simple example of a page that plays songs in chrome:

https://thomashunter.name/examples/chrome-audio-bug.html

Pay attention to how this song will continue to play in the background. Although it is very suitable for jukebox, it will drive online game players crazy

Is there any way to disable background playback of a single audio element in Chrome? Or, at least one callback, when the page loses focus, so I can run song. Stop()?

resolvent:

You can try using visibilitychange:

Here is a complete example https://jsfiddle.net/6001wsf9/

Tested with chrome 43.0.2357.78 on Android 5.0

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>