This page documents media-related stuff.
|
Table of Contents
|
Audio Background Playback
To play audio in the background, you will need to do the following:
- Add the following to the permissions section in your Manifest:
"audio-channel-content": {"description": "optional"}- Apply the following to your media object through JavaScript:
audio.mozAudioChannelType = 'content'; video.mozAudioChannelType = 'content'; //UNCONFIRMED -- PLEASE TEST THIS
Once you have done those two things, you can now play audio in the background. The user can navigate away from your app, and the music will continue playing.
Make sure your app is not too heavy, so that your app does not get unexpectedly killed in the background while music is playing.
Changing the Volume
Some devices do not have a volume rocker, so these devices will require an alternate way of changing the volume. You can allow users to change the volume using alternate keys by calling navigator.volumeManager.requestUp/Down(). The VolumeUp and VolumeDown keys already change the volume, so you don't need to bind those keys to requestUp/Down.
You can also call navigator.volumeManager.requestShow() to show the volume changer, without actually changing the volume.
2-Step Bug
On some devices, calling navigator.volumeManager.requestUp/Down() from the ArrowUp/Down keydown event will change the volume by two steps. A workaround is to just call requestShow() instead, however this will cause a minor inconvenience in which some devices may have to press ArrowUp twice to change the volume 1 step.
Choosing the Audio Channel
Depending on the device, the wrong channel may be changed on volume change. For example, on the Alcatel Go Flip 3, the ringtone & notices channel is changed by default, but on the Nokia 2720 Flip, the media channel is changed by default. You can manually choose the media channel with mozAudioChannelManager, however the app type needs to be privileged or higher.
navigator.mozAudioChannelManager.volumeControlChannel = 'content';
Notes:
- This will not return an error if you choose an invalid channel. So if you choose an invalid channel, the volume changer will be broken.
- The only known valid channel at the moment is content.
- There is no information on how to reset the volume control channel at this time.
