尝试捕获音频,但是即使授予了麦克风权限,在Safari 12上navigator.mediaDevices.enumerateDevices()还是NULL [英] Trying to capture audio but navigator.mediaDevices.enumerateDevices() is NULL on Safari 12 even with microphone permissions granted

查看:1062
本文介绍了尝试捕获音频,但是即使授予了麦克风权限,在Safari 12上navigator.mediaDevices.enumerateDevices()还是NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅相关问题: Navigator.mediaDevices.getUserMedia无法正常工作在iOS 12 Safari上

我们正试图从用户输入用户MediaDevices.getUserMedia和音频上下文中捕获音频

We are trying to capture audio from user input user MediaDevices.getUserMedia and Audio Context

当用户单击按钮时,我们会检查可用设备,然后捕获他们的音频流

When the user clicks a button we check for available devices and then we capture their audio stream

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 响应-因此,我们无法捕获音频流

This works fine on Chrome and Firefox, but on Safari 12 we are getting a Null response from the enumerate devices promise - despite allowing microphone permissions - and we because of that we aren't able to capture the audio stream

推荐答案

发生这种情况是因为Mobile Safari不会公开音频输入"类媒体设备.这是一个已知的限制.

It happens because Mobile Safari doesn't expose "audioinput" kind of media devices. This is a known limitation.

这篇关于尝试捕获音频,但是即使授予了麦克风权限,在Safari 12上navigator.mediaDevices.enumerateDevices()还是NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆