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
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.
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.
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);
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With