Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect whether a browser tab is playing audio or not?

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.

like image 448
Ramy Ben Aroya Avatar asked Nov 01 '16 09:11

Ramy Ben Aroya


1 Answers

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

like image 193
roberrrt-s Avatar answered Oct 25 '22 01:10

roberrrt-s