Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing sound from INACTIVE browser tab

Tags:

I have a control panel for restaurants and it plays an alert sound when an order is given. The problem is that when the control panel tab is not the active tab in Chrome (it's also same for Firefox) the alert sound doesn't play. After clicking the tab it plays the sound.

I see some sites (Facebook Chat, Cloudstats.me server alert, ...) play sound even if they are in inactive tab, so what is the workaround for this problem?

like image 716
Ali Caner Öner Avatar asked Oct 18 '15 09:10

Ali Caner Öner


People also ask

How do I find out what tab is playing a sound?

See the little speaker icon next to the X at the right? So obviously, when you have a bunch of tabs open and you see that one has the speaker icon, you know that's the tab that is generating the sound. You can either go to that tab and stop the video or whatever is causing the sound, or just close the tab.

How do I stop Google Chrome from playing sound?

Turn off sounds in Chrome by right-clicking on the tab and selecting the Mute Site option. If you aren't sure which tab is making the noise, look for a little speaker icon on the offending tab. To mute Safari sounds, look for the speaker icon in the address bar.

Why can't I hear audio from my browser?

Check Sound in Volume Mixer Right-click on the speaker icon in the lower-right corner. Click on Open Volume Mixer. If Chrome is already muted, unmute it and set the volume to 100.


1 Answers

Had a similar thing happen to me as well, we were trying to play a marketclock when the stock market opened and closed for the day. The issue we had was we tried to load the mp3 then play it when the condition is met. So originally I had.

var bell;

// Update the clock, countdown, and tooltips as needed.
function updateClock() {
    service.getMarketDate(function(data) {

        if (data.soundMarketBell) {
            if (!bell) {
                bell = new Audio('/sounds/marketclock.mp3');
            }
            bell.play();
        }
    });
}

var intervalId = $interval(updateClock, 1000);

By moving the resource loading to happen on page load and then just calling the Audio.play it fixed the issue

var bell = new Audio('/sounds/marketclock.mp3');

// Update the clock, countdown, and tooltips as needed.
function updateClock() {
    service.getMarketDate(function(data) {
        if (data.soundMarketBell) {
            bell.play();
        }
    });
}

// check for a time update every second
// to balance accuracy with performance
var intervalId = $interval(updateClock, 1000)

Browsers restrict loading resources when a tab is inactive

like image 165
YourGoodFriend Avatar answered Sep 23 '22 23:09

YourGoodFriend