我已经建立了一个Chrome扩展,可以捕捉屏幕活动和麦克风输入,并输出一个视频文件。自从
chrome.desktopCapture
无法录制音频
除了屏幕截图,我还将把麦克风放在独立的流中。所以:
//get screen stream
chrome.desktopCapture.chooseDesktopMedia(['screen'], null, (stream_id, opts) => {
let constraints = {video: mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: stream_id
}};
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
video_stream = stream;
});
});
//get mic stream
navigator.mediaDevices.getUserMedia({audio: true}).then((stream) => {
audio_stream = stream;
});
let master_stream = new MediaStream(video_stream);
master_stream.addTrack(audio_stream.getTracks()[0]);
最后,当我最终得到一个视频文件时,这个效果很好。我有屏幕和麦克风。
问:如果我要求Chrome也录制系统声音,为什么这项技术不起作用?
['screen']
到
['screen', 'audio']
,其他一切都一样,我最终在结果视频中没有麦克风。
getTracks()
在
master_stream
,我得到的是:
Array(3)
0: MediaStreamTrack {kind: "audio", id: "9ee3ee33-73ee-41e4-957c-d6fd3aaada43", label: "System Audio", enabled: true, muted: false, â¦}
1: MediaStreamTrack {kind: "audio", id: "ab2429a1-7f75-48f2-9ee1-6a4bfd7ca942", label: "Default - Microphone (Samson Meteor Mic) (17a0:0310)", enabled: true, muted: false, â¦}
2: MediaStreamTrack {kind: "video", id: "4ecb1929-31d0-4a79-8cbc-1a8759323c3b", label: "screen:0:0", enabled: true, muted: false, â¦}