3

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

islalobo
  • 507
  • 6
  • 17

1 Answers1

0

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

Aleksey Gureiev
  • 1,449
  • 11
  • 16