【问题标题】:Angular web-app microphone switching causes error `NotReadableError: Concurrent mic process limit`Angular Web-app 麦克风切换导致错误“NotReadableError:并发麦克风进程限制”
【发布时间】:2021-12-23 21:06:22
【问题描述】:

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

选择我想更换的新麦克风后,我收到了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;
            });
    }

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

【问题讨论】:

    标签: angular typescript webrtc openvidu


    【解决方案1】:

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

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

    您可以在请求另一个流之前停止当前流,方法是在其所有轨道上调用 stop。

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

    【讨论】:

    • track.stop() 正如我在下面的回答中提到的那样,它非常不稳定,而且实际上每次都不起作用。我尝试使用onended() 事件制作某种track.stop() 检查器,但这对我来说到目前为止还没有工作,由于某种原因它在 ngOninit() 之外也无法工作。所以我在下面的答案中的代码在某个组件的 ngOninit() 中,而它应该在我在问题中提到的 onMicrophoneSelected() 函数中
    • 对不起,我不能说为什么打电话给stop() 在任何情况下都不适合你。我不知道有任何错误。但这当然并不意味着没有。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多