我正在开发一个 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
在此处输入代码