我正在尝试构建一个Chrome扩展程序,用于通过扬声器音频(计算机音频)和麦克风音频捕获用户屏幕。使用RecordRTC中的示例我将下面拼凑在一起,但是当我打开录制的.webm
文件时,我根本听不到任何声音。
我还应该采取其他措施来获取音频吗?
下面是我的后台脚本的代码,删除了一些部分以使其更清晰。当有人单击开始记录按钮时,将调用startRecording()
函数。
const OPTIONS = {
type: 'video',
disableLogs: false,
mimeType: 'video/webm'
}
const captureUserMedia = callback => {
chrome.desktopCapture.chooseDesktopMedia(['screen', 'window', 'audio'], chromeMediaSourceId => {
const options = {
audio: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: chromeMediaSourceId,
echoCancellation: true
},
optional: []
},
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: chromeMediaSourceId
},
optional: []
}
};
navigator.mediaDevices.getUserMedia(options)
.then(callback)
.catch(err => new Error(err));
});
};
const startRecording = () => {
captureUserMedia(mediaStream => {
state.recordData = RecordRTC(mediaStream, OPTIONS);
state.mediaStream = mediaStream;
state.recordData.startRecording();
});
}
const stopRecording = () => {
state.recordData.stopRecording(function(videoURL) {
chrome.tabs.create({ url: 'show-video.html?video=' + videoURL });
});
state.mediaStream.getTracks().forEach(track => track.stop());
}