无法使用 Firefox 从 navigator.mediaDevices.getUserMedia 获取两个音频流



我需要从我服务中的另一个音频输入中录制视频(带有audiotrack)和另一个录音带。来自第二个麦克风的录制必须是可选的,并使用复选框控制。

请检查演示:

jsfiddle.net/x45h6cg3

function getMediaWithConstraints(audioSource, videoSource) {
    // webrtc does supports only fixed sizes for firefox 16:9 ratio.
    let w = 640;
    let h = 360;
    let constraints = {
        audio: { deviceId: audioSource ? { exact: audioSource } : undefined },
        video: {
            deviceId: videoSource ? { exact: videoSource } : undefined,
            aspectRatio: 1.7777777778,
            width: { min: w, max: w, ideal: w },
            height: { min: h, max: h, ideal: h }
        }
    };
    navigator.mediaDevices.getUserMedia(constraints)
        .then(gotStream).catch(errorCallback);
}
function getSecondMediaWithConstraints(secondAudioSource) {
    let audioConstraints = {
        video: false,
        audio: { deviceId: secondAudioSource ? { exact: secondAudioSource } : undefined }
    };
    navigator.mediaDevices.getUserMedia(audioConstraints)
        .then(gotSecondStream)
        .catch(errorCallback);
}

它在Chrome中运作良好,但在Firefox中投掷 MediaStreamError Aborterror"启动音频失败" 。必须通过Firefox提供支持。

您至少需要两个音频输入才能测试。

任何人都可以在Firefox上正确的流初始化?

firefox中有一个错误(用v67.0测试),您不能同时从两个不同的麦克风中获得音频流(参考:https://bugzilla.mozilla.org/show_bug.cgi?id = 1238038)。这似乎是导致您的问题的原因。


回答原始和 @kaiido的提琴(...我无法评论):他们提供了误导性结果,因为Getusermedia的承诺并不总是得到解决。由于口香糖调用无法满足预期,因此没有发生错误。这似乎是因为同时有两个未决的口香糖呼叫。

进行演示,这是两个小提琴:

  1. 并行:https://jsfiddle.net/6co2eh0d/

    • Kaiido的小提琴,在调用口香糖之前有额外的原木。表明正在称呼口香糖,但没有解决。
  2. 顺序:https://jsfiddle.net/73dqbs1p/

    • Kaiido的小提琴,但按顺序进行了两个口香糖调用。表明,当针对不同的音频设备解决口香糖时,发生了错误。
    // Call gUM one after the other, rather than having them done in parallel.
    getMediaWithConstraints(audioDeviceSelected, videoDeviceSelected)
        .then(() => {
            getSecondMediaWithConstraints(audioSecondDeviceSelected);    
        })
    

最新更新