navigator.mediaDevices.getUserMedia API 因错误“NotReadableError:并发麦克风进程限制"而拒绝. [英] navigator.mediaDevices.getUserMedia API rejecting with error "NotReadableError: Concurrent mic process limit."

查看:174
本文介绍了navigator.mediaDevices.getUserMedia API 因错误“NotReadableError:并发麦克风进程限制"而拒绝.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在活动媒体流(语音)期间 navigator.mediaDevices.getUserMedia 在连接到内部麦克风时工作正常,只要我切换到蓝牙设备并重新运行相同的 API 以获取最新的媒体流, 我收到错误 "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."

我浏览了很多论坛,正如许多人所建议的那样,当多个选项卡尝试访问麦克风或/和相机时,此错误通常发生在 Firefox、Mac OS 中.

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.

我确保在 Firefox 浏览器中只打开了一个选项卡,仍然看到相同的错误.

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

对此的任何线索将不胜感激.

Any leads on this shall be appreciated.

下面是代码片段

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);
});

返回以下错误信息

NotReadableError: Concurrent mic process limit.

注意:在 Chrome 和 Edge 中工作正常

NOTES: Works fine in Chrome and Edge

浏览器:Firefox 70.0.1(64 位)

Browser : Firefox 70.0.1 (64-bit)

操作系统:MacOS Mojave

OS : MacOS Mojave

推荐答案

NotReadableError: Concurrent mic process limit.

这意味着您现在不能在 Firefox 中为每个进程一次打开多个麦克风.此限制是 Mozilla 正在修复的已知错误.

实际上,这意味着您不能从您的站点打开多个麦克风(同源标签通常共享相同的过程).使用完麦克风后,请务必调用 track.stop().

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.

在尝试从其他麦克风获取音轨之前,先在现有麦克风音轨上调用 track.stop().

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);
  }
}

完成所有这些,但仍然获得与以前相同的麦克风

切换设备时,使用deviceId: {exact: deviceId}.即

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

这会告诉浏览器您想要此特定设备或故障,并避免 Firefox 中最近的回归.

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.

这篇关于navigator.mediaDevices.getUserMedia API 因错误“NotReadableError:并发麦克风进程限制"而拒绝.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆