Trying to capture audio but navigator.mediaDevices.enumerateDevices() is NULL on Safari 12 even with microphone permissions granted

☆樱花仙子☆ 提交于 2019-12-24 00:23:49

问题


See related question: Navigator.mediaDevices.getUserMedia not working on iOS 12 Safari

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
       });
    });

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

来源:https://stackoverflow.com/questions/56047028/trying-to-capture-audio-but-navigator-mediadevices-enumeratedevices-is-null-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!