How to play audio in background with firefox os?

2019-02-22 00:48发布

问题:

In my manifest file I've add the audio-channel-content in permissions:

"permissions": {
    "audio-channel-content":{"description":"Use the audio channel for the music player"}
}

In my index.html I've got an audio tag like:

<audio mozaudiochannel="content" preload="none" src="http://my-stream-url"></audio>

I can play my audio stream during 2mn:

  • The first one when the phone is unlock.
  • After 1mn my phone auto-lock the screen and it continue playing for another minute.

Does it possible to play this audio stream more than 1mn after the lock?

Thanks in advance.

回答1:

The code and permission block you have are correct and I can confirm it is working in Firefox OS 1.1. You can also do the whole thing in Javascript:

audio = new Audio();
audio.preload = 'none';
audio.mozAudioChannelType = 'content';


回答2:

It's because the wifi is closed after screen shutdown (auto-lock)?

Are you using the dev version of gaia? Wifi is set to always connect in product version.