WebAPI/AudioChannels
This API introduces the concept of a hierarchy of audio channels. The channels are prioritized as to allow "silencing all channels with priority lower than X".
The problems that we are trying to solve are:
- When the user answers a phone call, the sound from all apps should be silenced
- The alarm clock shouldn't be muted even if normal audio is muted. This to prevent the user oversleeping due to having muted the phone the previous day.
- When the user leaves an app, under normal circumstances the app should be muted.
- Some apps need to be able to opt in to not getting muted when the user leaves the app, such as the music player app or the radio app.
- When the volume keys are used it should change the volume for different audio types depending on context. For example while in the alarm app, the volume keys should adjust the alarm volume and not the "normal" volume.
https://etherpad.mozilla.org/sound-stream-types
The channels are:
- normal: UI sounds, web content, music, radio
- notifications: New email, incoming SMS
- alarm: alarm clock, calendar alarms
- telephony: phone calls, voip calls
- publicnotification: forced camera shutter sounds
We'll have separate mute and volume settings per channel. We'll additionally have a volume and mute setting for a "headphones" channel.
For now all sounds are directed through headphones/headset when they are plugged in. We discussed possibly making the alarm sound through both headphones and speaker, but we deemed this a non-v1 feature.
For now all audio channels except "telephony" never use the built-in earpiece. I.e. they always use the speaker or headphones/headset. We might introduce using the built-in earpiece for "normal" sounds in a future version.
API
interface AudioChannelManager : EventTarget { muteChannelsBelow(DOMString type); unmuteChannels(); readonly attribute DOMString[] mutedChannels; attribute EventHandler onmutedchange; // We might not need this headphones section for v1. readonly attribute boolean headphones; attribute EventHandler onheadphoneschange; // Always fired before audio start playing through the new channel attribute boolean telephonySpeaker; // When set to true, the "telephony" channel uses the speaker. // I.e. this is the same as navigator.telephony.speakerEnabled // Might not be needed for v1 if we aren't targetting VoIP apps. attribute DOMString volumeControlChannel; // The channel whose volume is changed if the user presses the // volumeup/down buttons. Defaults to "normal". }
When muteChannelsBelow is called, it changes the mutedChannels property of all AudioChannelManager instances in all apps. Also all audio for all muted channels are muted. The audio's are not automatically paused. Instead applications are expected to listen to the "mutedchanged" event and call pause() as they see fit, for example if they want to resume music where it was when the music was muted.
Likewise, when when the user leaves an app, the mutedChannels property changes to include all channels.
The