在仔细考虑了这个问题后,我发现:我可以使用getDisplyMedia
方法,但它不支持仅音频请求,所以我尝试获取音频和视频的流,然后像这样从中获取音轨:
var speaker = new MediaStream;
if (navigator.getDisplayMedia) {
navigator.getDisplayMedia({
video: true ,
audio: true
}).then(stream => {
speaker.addTrack(stream.getAudioTracks()[0].clone());
// stopping and removing the video track to enhance the performance
stream.getVideoTracks()[0].stop();
stream.removeTrack(stream.getVideoTracks()[0]);
}).catch(() => {
console.error('failed')
});
} else if (navigator.mediaDevices.getDisplayMedia) {
navigator.mediaDevices.getDisplayMedia({
video: true ,
audio: true
}).then(stream => {
speaker.addTrack(stream.getAudioTracks()[0].clone());
// stopping and removing the video track to enhance the performance
stream.getVideoTracks()[0].stop();
stream.removeTrack(stream.getVideoTracks()[0]);
}).catch(() => {
console.error('failed')
});
}
我知道这并不能完美地解决问题,但我认为它很有用。
“仍在工作并等待更多解决方案”