Version: Smart Feature Phone 3.0

Audio Channels API

Description#

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.


Concepts and usage#

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. The <audio> and <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 nameimportanceUsed forApp permission level
normal1UI sounds, app and web contentPWA
content2Music, radio, videoPWA
notification3New email, incoming SMSSigned
alarm4Alarm clock, calendar alarmsSigned
ringer5Incoming phone callsCore
telephony6Ongoing phone calls, VOIP callsCore
publicnotification7Forced camera shutter soundsCore

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.


AudioChannels interfaces#

AudioChannelManager

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.

HTMLMediaElement and AudioContext extentions

HTMLMediaElement and 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.