![](/img/trans.png)
[英]Firefox never resolving navigator.mediaDevices.getUserMedia()
[英]Can't get two audio streams from navigator.mediaDevices.getUserMedia with Firefox
我需要在服務中錄制視頻(帶有音頻軌道)和來自另一個音頻輸入的另一個音頻軌道。 第二個麥克風的錄音必須是可選的,並通過復選框進行控制。
請檢查它的演示:
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的承諾不一定總是得到解決,它們提供了誤導性的結果。 由於gUM調用未按預期完成,因此不會發生錯誤。 這似乎是因為同時有兩個待處理的gUM調用。
為了演示這一點,這里有兩個小提琴:
平行: https : //jsfiddle.net/6co2eh0d/
順序的: https : //jsfiddle.net/73dqbs1p/
// Call gUM one after the other, rather than having them done in parallel. getMediaWithConstraints(audioDeviceSelected, videoDeviceSelected) .then(() => { getSecondMediaWithConstraints(audioSecondDeviceSelected); })
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.