【问题标题】:Web Audio Api : navigator.mediaDevices.getUserMedia ---> Error:NotReadableError: Concurrent mic process limitWeb Audio Api : navigator.mediaDevices.getUserMedia ---> Error:NotReadableError: Concurrent mic process limit
【发布时间】:2021-05-25 21:20:36
【问题描述】:

我正在开发一个 3D 环境,它将两个麦克风与我的场景中的特定几何形状连接起来,在本地运行。 我希望能够在使用哪个麦克风之间切换(当我按下键 A 时使用 mic1 和当我按下键 B 时使用 mic 2 )。 我得到的错误是: Firefox ----> Error:NotReadableError: Concurrent mic process limit。 Chrome -> 没有错误,它只是不切换设备

我该如何解决?我试图停止流,但也许我做得不对,有什么建议吗?

async function openMic(nodein){ 

 // inputDevices is an array with the deviceIds
 await  navigator.mediaDevices.getUserMedia ({audio: { deviceId: {exact: 
                         inputDevices[nodein]}}, video: false}) 
 
    .then(function(stream) {
    console.log('THE DEVICE IS: '+ thisdev);    

    //soundNodesArray has objects that represent different sources
    soundNodesArray[nodein].source=context.createMediaStreamSource(stream);

    //making our source a stream connect source with Gain node
    soundNodesArray[nodein].source.connect(soundNodesArray[nodein].volume);
                
    //connect Gain node with Panner node                     
    soundNodesArray[nodein].volume.connect(soundNodesArray[nodein].panner);
                
    //connect the Panner Node with the Destination node                  
    soundNodesArray[nodein].panner.connect(context.destination);
 })
.catch(function(e){
    alert('Error:'+e);
    });
        
}       

为了停止轨道,我先调用这个函数:

    async function closeMic(nodeout) {
await   navigator.mediaDevices.getUserMedia({audio: true, video: false})
    .then(function(mediaStream) {
        const tracks = mediaStream.getTracks();
          
        tracks.forEach(function(track) {
        track.stop();
        console.log('STOPPED STREAM ?????????');
        });
    })
  
    soundNodesArray[nodeout].source = null;
  }
enter code here

在此处输入代码

【问题讨论】:

  • 欢迎来到 SO。请edit您的问题向我们展示切换麦克风的代码。当您停止使用麦克风时,不要忘记.stop() 流中的所有曲目。
  • 这是stackoverflow.com/questions/59068146/… 的副本。我在那里添加了一个答案。

标签: firefox web-audio-api getusermedia navigator mediadevices


【解决方案1】:

await ... .then() 不正确。

要打开您的信息流,请执行以下操作。

let stream  // keep the stream so you can stop it later.
async function openMic(nodein){ 
  try {
    // inputDevices is an array with the deviceIds
   stream = await navigator.mediaDevices.getUserMedia (
                 {audio: { deviceId: {exact: inputDevices[nodein]}},
                  video: false}) 
 
   //soundNodesArray has objects that represent different sources
   soundNodesArray[nodein].source=context.createMediaStreamSource(stream)

   ...
  } catch (e) {
    alert('Error:' + e)
    console.error(e)
  }
}

稍后,为了停止流,停止它的所有轨道并忘记它的存在。不要使用.getUserMedia() 试图让另一个流停止。而是停止你已经拥有的那个。

const tracks = stream.getTracks()
tracks.forEach(track => {track.stop()})
stream = undefined

我不熟悉 AudioContext 的东西;在开始新的直播之前,您可能也必须停止这些内容。

最好先停止一个流,然后再使用getUserMedia() 启动另一个流。某些浏览器允许您在停止另一个流之前启动一个流。其他人没有。

【讨论】:

  • 谢谢!我尝试了更改,毕竟不起作用的部分是我试图停止流。
  • await stream = 是错误的,因为它使stream 成为一个承诺。你想要stream = await
  • 天啊! (捂脸)你是对的。感谢您的更正,@jib
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-24
  • 2021-01-03
  • 1970-01-01
  • 2015-08-07
  • 2013-05-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多