Search code examples
javascriptaudiopermissionsfirefox-os

Audio-capture on a Firefox OS device or simulator


I'm trying to get audio capture working on Firefox OS (v1.3, though I've tried Firefox OS 2 and that doesn't work either) but I'm struggling to get it working.

I have added the following to my manifest.webapp:

permissions": {
    "audio-capture": {},
  }

I then have the following code in a file recorder.js:

window.AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext();

function initAudio()
{
    window.alert( "Trying..." );
    navigator.mozGetUserMedia(  {
                                audio: true,
                                video: false
                            },
                            function( stream )
                            {
                                window.alert( "GO!" );
                            },
                            function( error )
                            {
                                window.alert( "ERROR! :(" );
                            } );


}

window.addEventListener('load', initAudio );

The "Trying..." message is called as the app starts up but I never see "GO!" or "ERROR! :(". Has anyone got any ideas on how to get this working? It seems to make no sense. The same code through firefox (the browser) seems to work fine. I get asked to give permission for audio capture and then I see the "GO!" message.

So has anyone got any idea how to get this working under firefox OS?


Solution

  • One of my colleagues cracked it. It doesn't work on the simulator at all but on an actual device setting the manifest "type" to "web" solves the problem (we originally had it selected as "privileged"!).

    Desperately confusing because it says you ned to be at "least" hosted for it to work and as best we can tell "web" is a lesser type than "hosted" and "privileged" is a greater type than both "web" and "hosted".

    Hope that saves someone the 2 days of pain we've just been through!