Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigator.mediaDevices.getUserMedia API rejecting with error "NotReadableError: Concurrent mic process limit."

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

like image 991
user3214392 Avatar asked Nov 27 '19 10:11

user3214392


1 Answers

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.

like image 159
jib Avatar answered Nov 07 '22 22:11

jib