contact@allblognow.comLogin
all blog now

October 14, 2023

Manage Audio Focus Across Tabs in Chrome

If you're constantly having to mute one noisy tab after another in Chrome, an experimental feature could help. Chrome is adding a new flag called manage audio focus across tabs that aims to improve the quality of audio mixing when you switch between multiple tabs.

The feature, which is available now in the developer (Dev) channel of Chrome, will stop any other audio playing on a page when you move to a different tab that plays sound. It's not clear whether the feature will make any difference in overall performance, but Google is clearly pushing for a better mix of sound on the browser, and the ability to mute sounds on other sites from within the same browser seems like a good start.

Android's ARC framework provides the ability to request audio focus from other apps running on the system, and Chrome uses this API in its manage audio focus across tabs feature. An app that has requested audio focus is known as a MediaSession, and it can be either a persistent or transient session. Persistent sessions block other audio output unless they are the current focus session; transient sessions allow other sound to play but lower their own volume.

Occasionally the system cannot grant a focus request because the previous focus session is locked, for example when someone's on a call and listening to music. To handle this, your app can set an onAudioFocusChangeListener to be called when the current focus is changed. The listener can implement a custom callback that either pauses or ducks the app's audio output.