Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if a Chrome tab is playing audio?

I'd like to execute a console command on a specific tab and receive a boolean answer whether the tab is playing audio. (Usually stated as a little speaker icon near the tab's title)

Can this be done?

like image 753
Omer H Avatar asked Jan 14 '17 12:01

Omer H


People also ask

How can I tell which tab is making a sound?

Visit the tabs tray by tapping the number next to the address bar: You'll see your open tabs. Look for the pause icon on the tab list to see which tabs are playing audio. This icon is a button that allows you to stop the sound.

How do you find what is playing on Chrome?

Just click the icon in the top right corner of Chrome on desktop, open the new media hub and manage what's playing from there.

How do I stop tabs from playing sound in Chrome?

Chrome. Google's browser displays a little speaker icon on any tab that is currently playing audio. To mute the audio for a tab, right-click the tab and choose Mute site. You can perform this maneuver without leaving your current tab.

How do I find out what video is playing?

Shazam, SoundHound & Music Recognition Apps Shazam: Available for both Android and iOS users, this one of the most popular song recognition apps on the market. After downloading the app to your device, you can easily ask it what song is playing and get the song details.


1 Answers

You can detect if a Chrome tab is playing audio with a Chrome Extension, using the chrome.tabs API. The API provides a boolean audible property, as described below:

Whether the tab has produced sound over the past couple of seconds (but it might not be heard if also muted). Equivalent to whether the speaker audio indicator is showing.

Source: https://developer.chrome.com/extensions/tabs

There's no way to access the tabs from the console itself, as it is run from the context of the current page. In the background page of a Chrome Extension, you have access to all the tabs, and you can query them using the API outlined above. Your extension can simply provide a panel that displays a list of all the open tabs and a flag to say whether the audio is playing.

Aside: If you just want to quickly mute HTML5 Audio/Video in the current tab using the Chrome console, you can run the following (the $$ is equivalent to document.querySelectorAll()):

$$('video', 'audio').forEach((element) => element.muted = true);
like image 99
Gideon Pyzer Avatar answered Sep 30 '22 11:09

Gideon Pyzer