Ramy Ben Aroya Ramy Ben Aroya - 4 months ago 34
Javascript Question

Detect whether a brower tab is playing sound

I am looking for a way to detect whether a sound is being played in the current tab of Chrome. I would like to emphasise 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