是否可以检测浏览器选项卡是否正在播放音频?
Is it possible to detect whether a browser tab is playing audio or not?
我正在寻找一种方法来检测是否正在 Chrome 的 当前选项卡 中播放声音。我想强调的是,上下文是一个网络应用程序,不是 chrome 扩展,也不是单个音频元素。我的假设是浏览器 "knows" 选项卡通过在选项卡 header 中显示一个声音图标来播放声音,所以我猜测有某种浏览器 HTML5 API为此。
简单回答:否
长答案:
在这种情况下,有些是最好的情况。
Chrome 有一个仅供开发人员使用的 API 浏览器,可以挂接连接的音频设备,但不可能在真实环境中使用它。 (source)
The chrome.audio API is provided to allow users to get information
about and control the audio devices attached to the system. This API
is currently only implemented for ChromeOS.
Jared Sohn 也回答了一个有趣的解决方案,原理是一个插件(应该也可以是 web)扫描网页以查找播放音频的文件。您可以为您的网页重写这样的内容(通过获取所有可能的音频来源并单独检查它们)。 (source)
Perhaps the closest that you can do is something similar to what the
MuteTab Chrome extension does (written by me,
http://www.github.com/jaredsohn/mutetab), which basically scans the
page for object, embed, audio, video, and applet tags and hides them
from the page. Unfortunately, this misses web audio
我正在寻找一种方法来检测是否正在 Chrome 的 当前选项卡 中播放声音。我想强调的是,上下文是一个网络应用程序,不是 chrome 扩展,也不是单个音频元素。我的假设是浏览器 "knows" 选项卡通过在选项卡 header 中显示一个声音图标来播放声音,所以我猜测有某种浏览器 HTML5 API为此。
简单回答:否
长答案:
在这种情况下,有些是最好的情况。 Chrome 有一个仅供开发人员使用的 API 浏览器,可以挂接连接的音频设备,但不可能在真实环境中使用它。 (source)
The chrome.audio API is provided to allow users to get information about and control the audio devices attached to the system. This API is currently only implemented for ChromeOS.
Jared Sohn 也回答了一个有趣的解决方案,原理是一个插件(应该也可以是 web)扫描网页以查找播放音频的文件。您可以为您的网页重写这样的内容(通过获取所有可能的音频来源并单独检查它们)。 (source)
Perhaps the closest that you can do is something similar to what the MuteTab Chrome extension does (written by me, http://www.github.com/jaredsohn/mutetab), which basically scans the page for object, embed, audio, video, and applet tags and hides them from the page. Unfortunately, this misses web audio