getDisplayMedia的音频捕获在我的Macbook中不适用于Chrome,当Chrome要求用户共享屏幕时,它没有被要求检查音频共享,它只使用MediaStream录制视频。但在我的Windows电脑中,它完全支持Chrome浏览器的视频和音频捕获,它会要求用户检查是否共享音频。我可以问一下,这是因为支持问题还是代码问题?我正在macbook中使用最新版本的chrome以下是我的代码:
navigator.mediaDevices
.getDisplayMedia({
video: true,
audio: true
})
.then((Mediastream) => {
vm.$set(vm, 'isRecording', true);
if (vm.isInitiator || vm.isConnector) {
if (localStream) {
let localAudio = new MediaStream();
localAudio.addTrack(localStream.getAudioTracks()[0]);
if (Mediastream.getAudioTracks().length != 0) {
let systemAudio = new MediaStream();
systemAudio.addTrack(Mediastream.getAudioTracks()[0]);
let audioContext = new AudioContext();
let audioIn_01 = audioContext.createMediaStreamSource(localAudio);
let audioIn_02 = audioContext.createMediaStreamSource(systemAudio);
let dest = audioContext.createMediaStreamDestination();
audioIn_01.connect(dest);
audioIn_02.connect(dest);
let finalAudioStream = dest.stream;
Mediastream.removeTrack(Mediastream.getAudioTracks()[0]);
Mediastream.addTrack(finalAudioStream.getAudioTracks()[0]);
} else {
Mediastream.addTrack(localStream.getAudioTracks()[0]);
}
}
}
this.createRecorder(Mediastream);
})
.catch((err) => {
this.getUserMediaError(err);
});
不幸的是,这是Chrome在macOS上的限制。根据";caniuse.com";,
在Windows和Chrome操作系统上,可以捕获整个系统的音频,但在Linux和macOS上,只能捕获选项卡的音频。
https://caniuse.com/mdn-api_mediadevices_getdisplaymedia_audio_capture_support