我正在使用getUserMedia API從Chrome擴展中捕獲屏幕並錄製音頻(在一起)。 api捕捉屏幕,記錄視頻但不捕獲音頻。getUserMedia API無法捕獲音頻以及來自Chrome擴展的視頻
Chrome版本:55
音頻未被捕獲的任何原因。 api是否有任何限制或者我們是否需要使用任何其他api來捕捉視頻+音頻? 請找到下面的代碼片段。 (下面的代碼存在於background.js中)
(嘗試傳遞約束作爲audio:true,video:true,但是這並不奏效,它引發了一個錯誤(Error - getUserMedia()failed:[object NavigatorUserMediaError ]))
chrome.desktopCapture.chooseDesktopMedia(['screen','audio'],
function onAccessApproved(id) {
const constraints = { "video": {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: id,
minWidth: 1280,
minHeight: 720,
maxWidth:1280,
maxHeight:720
}
}, "audio" : {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: id}} };
navigator.mediaDevices.getUserMedia(constraints).then(gotMedia).catch(e => { console.error('getUserMedia() failed: ' + e);
});
function gotMedia(stream) {
theStream = stream;
var video = document.createElement('video');
video.src = URL.createObjectURL(stream);
video.srcObject = stream;
try {
recorder = new MediaRecorder(stream, {mimeType : "video/webm"});
} catch (e) {
console.error('Exception while creating MediaRecorder: ' + e);
return;
}
theRecorder = recorder;
recorder.ondataavailable =
(event) => { recordedChunks.push(event.data); };
recorder.start(100);
stream.getVideoTracks()[0].onended = function() {
download();
};
}
function download() {
theRecorder.stop();
theStream.getTracks().forEach(track => { track.stop(); });
var blob = new Blob(recordedChunks, {type: "video/webm"});
var url = URL.createObjectURL(blob);
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = 'test.webm';
a.click();
// setTimeout() here is needed for Firefox.
setTimeout(function() { URL.revokeObjectURL(url); }, 100);
}
_「這是拋出一個錯誤。」_錯誤是什麼? – guest271314
錯誤:getUserMedia()失敗:[對象NavigatorUserMediaError] – Anil
是協議'https:'? – guest271314