The Audio Channels API allowing you to place your app audio content into a hierarchy of importance, which dictates when the audio will be paused and resumed in response to other audio playing and actions occurring and allows you to control the volume of different types of audio independently from one another.
Use case examples:
You want your audio player app to continue playing audio even when it is running in the background so you can do other things as it plays, but you want it to pause when someone rings your phone.
When you mute your phone you don't want to also mute your wake up alarm for the next morning.
The AudioChannels API extends the HTMLMediaElement and AudioContext interfaces with (among other things) a mozAudioChannelType property that can be set to the channel you want your audio to be played in.
<video> elements can also be used to set this value via the mozaudiochannel attribute.
When your audio is placed into a channel, it is generally paused (or interrupted) by audio in a higher priority channel being played.
Audio in the least important channel — normal — is also paused by its app being put into the background (this is not the case with the other channels).
The audio channels are as follows:
|Channel name||importance||Used for||App permission level|
|normal||1||UI sounds, app and web content||PWA|
|content||2||Music, radio, video||PWA|
|notification||3||New email, incoming SMS||Signed|
|alarm||4||Alarm clock, calendar alarms||Signed|
|ringer||5||Incoming phone calls||Core|
|telephony||6||Ongoing phone calls, VOIP calls||Core|
|publicnotification||7||Forced camera shutter sounds||Core|
Each channel has a separate mute and volume setting, to provide more granular control over the different parts of audio on your device. These are accessed using the audioChannelManager object via the navigator.b2g.audioChannelManager property.
Note: If you have two apps playing audio in the content channel, only the one in the foreground can play audio, while the other is interrupted. When the foreground app is put into the background with audio playing, it will not be muted, as per normal "content" behaviour.
Includes some features for managing your device's audio channels, including setting what channel's volume to affect when the volume buttons are pressed inside a particular app.
AudioContext are extended with some proprietary features for controlling audio channels,
including setting what audio channel the media is in, and events that fire when the audio is interrupted, and resumes playing.