If you want to have you own media playing app to be able to run at background, and/or has the ability to interrupt other playing audio, please view this article for what to do.
Audio Channel Permission
You need to specify this permission in the manifest of your app.
And yes, this means we don’t allow a web page without the manifest to play at background.
1 2 3 |
|
The content
represents the name of the audio channel.
Note: Video’s permission also uses the same audio-channel-content
.
Audio Channel Types
We have five audio channels currently:
normal
: Default channel of any media element, including video.content
: Especailly stands for content like music.notification
: Include desktop-notification soundsringer
: Incoming call ringeralarm
: Alarm has a specific requirement to interrupt any other channel above.telephony
: Voice.
Volume Settings
- Normal and content channel are sharing the same volume settings.
- Notification and ringer are another set.
- Other has its own settings key.
Audio Competing Rules
- We’re interrupting the lower channel when higher channel occurs.
- If the same channel are playing and using content channel, the one who gets visibility (go to foreground) would be the winner.
- The foreground page/app is always playable. However the channel type decides it could interrupt background playing content or not.
- The background page/app is playable if and only if the background is causing by screen off, and the page/app is the current displayed one.
I would explain the rules more in another article ;)
[Statically] HTML Media Element
You could assign audio channel type to the media elements in HTML.
1 2 |
|
Please keep in mind you need relevant channel permission.
Note: It’s
mozaudiochannel
instead ofmozaudiopchanneltype
here.
[Dynamically] Javascript
Sometimes we need to dynamically generate the player element:
1 2 3 4 5 |
|
Change the channel of the audio to another type is not allowed.
You should create another audio/video instance if you want to be played in another channel.
(OPTIONAL) If you want to know you’re interrupted by higher channel
Add mozinterruptbegin/mozinterruptend event handler if you need to do something with interruptions.
1 2 3 4 5 6 |
|
Notices
- Even if your are developing a HTML5 video playing app, and we all know that video shouldn’t be played at background due to strange UX, you should also consider to set content channel because video is expected to interrupt the current background playing media.