查看相关问题:Navigator.mediaDevices.getUserMedia not working on iOS 12 Safari
我们正试图从用户输入用户MediaDevices.getUserMedia和音频上下文中捕获音频
当用户单击按钮时,我们会检查可用设备,然后捕获其音频流
let enumDevicePromise = navigator.mediaDevices.enumerateDevices()
.then(devices => devices.find(d => d.kind === "audioinput" && d.label !== "" && d.deviceId === "default"))
.catch((error) => {
// handle error
});
this.handleCheckEnumeratedDevices(enumDevicePromise); // capture device in backend
.....
navigator.mediaDevices
.getUserMedia({
audio: true,
video: false,
})
.then(stream => {
let AudioContext = window.AudioContext || window.webkitAudioContext;
if (AudioContext) {
let context = new AudioContext();
let source = context.createMediaStreamSource(stream);
let processor = context.createScriptProcessor(4096, 1, 1);
source.connect(processor);
processor.connect(context.destination);
processor.onaudioprocess = (event) => {
let audioIn = event.inputBuffer.getChannelData(0);
this.sendMessage(this.toInt16(audioIn));
}
} else {
// handle error, ie, Audio Context not supported
}
}).catch((error) => {
// handle error
});
});
这在Chrome和Firefox上可以正常运行,但是在Safari 12上,尽管允许使用麦克风权限,但枚举设备的承诺却得到了 Null 响应-因此,我们无法捕获音频流
答案 0 :(得分:0)
发生这种情况是因为Mobile Safari不会公开“音频输入”类媒体设备。这是一个已知的限制。