首页 > 解决方案 > Angular Web-app 麦克风切换导致错误“NotReadableError:并发麦克风进程限制”

问题描述

我正在尝试实现麦克风切换功能,在浏览器上进行实时通话时,我可以用新的麦克风替换当前正在使用的麦克风。

选择要更改为的新麦克风后,我收到一条NotReadableError: Concurrent mic process limit.错误消息。此错误消息只能在 firefox 上复制,在 chromium 浏览器上不会显示错误,但是无法切换到另一个麦克风的问题仍然存在。

这是因为在添加新设备之前之前的设备没有被停用/销毁,这可以从此处的权限图标中看到:

在此处输入图像描述

旧麦克风仍处于活动状态,因此在允许新设备时,我收到并发麦克风进程限制错误。

我正在使用 replaceTrack() 切换到新选择的设备,并且在选择要激活的新麦克风时运行以下函数。

async onMicrophoneSelected(event: any) {

// selectedDeviceId holds the deviceId of the microphone i want to switch to

        const selectedDeviceId = event?.value;

        var newAudioTrack;
        var constraints;
        var mediaStream: MediaStream;
        var audioTrack: MediaStreamTrack;

// Looping through all available devices here 

        await navigator.mediaDevices.enumerateDevices().then((res) => {
            res.forEach((device) => {

                // Here checking if the available device is an audioinput and if its id matches the one which we want to swap to.

                if (device.kind === 'audioinput' && device.deviceId === selectedDeviceId) {
                    newAudioTrack = device;

                    // constraints specified here with new deviceId of microphone

                    constraints = {
                        video: { facingMode: 'user' },
                        audio: { deviceId: { exact: newAudioTrack['deviceId'] } },
                    };

                }
            });
        });     

        // Passing constraints into mediaStream

        mediaStream = await navigator.mediaDevices.getUserMedia(constraints);
        audioTrack = mediaStream.getVideoTracks()[0];

        // Custom replaceTrack() function here 

        this.localUsersService
            .getWebcamPublisher()
            .replaceTrack(audioTrack)
            .then(() => {
                this.publishAudio(true);
                this.hasAudioDevices = true;
            });
    }

在切换到新的麦克风和摄像头权限之前,如何完全停用以前的麦克风/摄像头?

标签: angulartypescriptwebrtcopenvidu

解决方案


正如您已经提到的,这是当前正在处理的 Firefox 中的一个限制。

https://bugzilla.mozilla.org/show_bug.cgi?id=1238038

您可以通过在其所有轨道上调用 stop 来停止当前流,然后再请求另一个流。

mediaStream.getTracks().forEach((track) => track.stop());

推荐阅读