是否有可能检测浏览器选项卡是否播放音频? [英] Is it possible to detect whether a browser tab is playing audio or not?

查看:148
本文介绍了是否有可能检测浏览器选项卡是否播放音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来检测是否在Chrome的当前标签中播放了声音。我想强调的是,上下文是一个Web应用程序,不是Chrome扩展程序,也不是一个音频元素。我的假设是,浏览器知道该标签正在播放声音,通过在标签标题中显示一个可听图标,所以我猜测这里有某种浏览器HTML5 API。


<解决方案

简单的答案:没有

b
$ b

在这种情况下,一些什么是最好的情况。
Chrome在浏览器中有一个dev-only API,可以连接音频设备,但在真实环境中无法使用它。 (source)


chrome.audio API是为了让用户获得
的信息并控制连接到系统的音频设备而提供的。此API
目前仅适用于ChromeOS。


Jared Sohn也有一个有趣的解决方案,原理是一个插件(应该可能是web)也会扫描网页播放音频的文件。您可以为您的网页重写这样的内容(通过抓取所有可能的音频源并单独检查它们)。 (来源)


也许最接近你可以做的是类似于
MuteTab Chrome扩展所做的事情(由我写的,
http://www.github.com/jaredsohn/mutetab ),它基本上扫描
页面中的对象,嵌入,音频,视频和applet标记并隐藏它们
从页面。不幸的是,这会错过网络音频


I am looking for a way to detect whether a sound is being played in the current tab of Chrome. I would like to emphasize that the context is a web app and not a chrome extension nor a single audio element. My assumption is that the browser "knows" that the tab is playing sound by displaying an audible icon in the tab header, so I am guessing that there is some kind of browser HTML5 API for that.

解决方案

Simple answer: no

Long answer:

Some-what-ish would be the best case in this context. Chrome has a dev-only API for it's browser that hooks on audio devices connected, but it's not possible to use this in a real environment. (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.

There is also an interesting solution answered by Jared Sohn, the principle is that a plugin (should be web possible as well) scans the webpage for files playing audio. You could rewrite something like this for your webpage (by grabbing all possible sources for audio and checking them individually). (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

这篇关于是否有可能检测浏览器选项卡是否播放音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆