12

During an active media flow(voice) navigator.mediaDevices.getUserMedia works fine when connected to internal mic, as soon as I switch to Bluetooth device and rerun the same API to fetch the latest media stream, I get the error "NotReadableError: Concurrent mic process limit."

I browsed throw many forums, as suggested by many that this error generally occurs in Firefox, Mac OS when multi tabs are trying to access mic or/and camera.

I made sure that only single tab is opened in Firefox browser, still see the same error.

Any leads on this shall be appreciated.

Below is the code snippet

constraints = {
    "audio": {"deviceId": deviceId },
    "video": false
}

let temp;
navigator.mediaDevices.getUserMedia(constraints).then(function(stream){
    temp = stream;
}).catch(function(err) {
  console.log(err.name + ": " + err.message);
});

Return below error message

NotReadableError: Concurrent mic process limit.

NOTES: Works fine in Chrome and Edge

Browser : Firefox 70.0.1 (64-bit)

OS : MacOS Mojave

jib
  • 40,579
  • 17
  • 100
  • 158
user3214392
  • 245
  • 4
  • 15
  • How are you switching to a bluetooth device? Programmatically? Firefox can't handle more than one microphone at a time in the same process so be sure to `track.stop()` the old one before requesting a new mic. – jib Nov 28 '19 at 02:27
  • I switch the device manually which triggers `navigator.mediaDevices.ondevicechange` . I tried `track.stop()` as soon as the ondeviceChange is triggered and update the peer connection object track with current media track but in Firefox `navigator.mediaDevices.getUserMedia()` always returns the internal mic stream which I had already stopped. Thanks for your suggestion, I will debug it more and see if I found any workaround. – user3214392 Dec 02 '19 at 06:27
  • 1
    Could you try waiting 200 ms after ondevicechange before calling `getUserMedia` again? I'd be curious to see if this fixes it. If so, this would qualify as a bug. – jib Dec 18 '19 at 15:30

1 Answers1

6

NotReadableError: Concurrent mic process limit.

This means you cannot open more than one microphone at a time, per process, in Firefox right now. This limitation is a known bug that Mozilla is working on fixing.

In practice, this means you cannot open more than one microphone from your site (same-origin tabs typically share the same process). Make sure to call track.stop() when you're done with a mic.

Comes up during device switching

Few sites actually need to use two mics at once. But sites still run into this bug when switching from one microphone to another, because they generally open the new microphone before closing the old one.

Workaround

Call track.stop() on your existing microphone track, before attempting to obtain a track from a different microphone.

This strategy is similar to mobile where only one camera can be opened at once. The best approach is a fallback strategy: only stop the old track if necessary (that way there's no impact on other browsers):

async function getUserMedia(constraints, oldTrack) {
  try {
    return await navigator.mediaDevices.getUserMedia(constraints);
  } catch (e) {
    if (e.name != "NotReadableError") throw e;
    oldTrack.stop();
    return await navigator.mediaDevices.getUserMedia(constraints);
  }
}

Done all that, but still get the same mic as before

When switching devices, use deviceId: {exact: deviceId}. I.e.

const constraints = {
    audio: {deviceId: {exact: deviceId}},
};

This tells the browser you want this specific device or failure, and avoids a recent regression in Firefox.

While fallbacks to other devices are normally good, they're not when the user is trying to pick a specific device.

jib
  • 40,579
  • 17
  • 100
  • 158