'Microphone not available in firefox

I'm trying to check permission of microphone and then start recording using this code, the following code is working on chrome but not working on firefox. It says microphone not available

  navigator.permissions.query(
        { name: 'microphone' }
    ).then(permissionStatus => {
        console.log(permissionStatus.state); // granted, denied, prompt
        if(permissionStatus.state != 'granted')
        {  
          alert('Please allow your microphone');
        }
        else
        {
          this.startRecording();
  
        }
        let self=this;
        permissionStatus.onchange = function(){
          if(this.state!='granted')
          {
          }
          else
          {
            self.mic_permission=true;
          }
          console.log("Permission changed to " + this.state);
        } 
    }).catch((error) => {
      //console.log('Got error :', error);
  });


Solution 1:[1]

The Permissions API is still experimental. Firefox currently does not support the microphone permission (See here).

Use the MediaDevices API (See here) instead:

function getLocalStream() {
    navigator.mediaDevices.getUserMedia({video: false, audio: true}).then( stream => {
        window.localStream = stream; // A
        window.localAudio.srcObject = stream; // B
        window.localAudio.autoplay = true; // C
    }).catch( err => {
        console.log("u got an error:" + err)
    });
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marc