Capacitor: WebRTC audio, "could not start audio source"

Created on 15 Sep 2018  路  5Comments  路  Source: ionic-team/capacitor

My app uses WebRTC audio fine in the browser, but when I open the app on my Android phone, I get the console error "DOMException: Could not start audio source".

Here's how I'm trying to read audio:
const stream = await navigator.mediaDevices.getUserMedia({audio: true, video: false});

I have given my app the Android microphone permission (<uses-permission android:name="android.permission.RECORD_AUDIO" />).

Most helpful comment

Looks like RECORD_AUDIO permission is not enough, you also need
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

But this will only work on Android 5, on Android 6+ you'll need to manually request the permissions and the user will have to grant them.

All 5 comments

Looks like RECORD_AUDIO permission is not enough, you also need
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

But this will only work on Android 5, on Android 6+ you'll need to manually request the permissions and the user will have to grant them.

Just saw we can see when the webview permissions are requested, I can use that to request the required native permissions too, will work on a PR.

I installed Capacitor beta 8 and I now get the prompt for "do you want to allow to record audio?". However, after clicking yes, when attempting to read media devices, I get DOMException: Permission denied.

Can you create a new issue with your code? I鈥檝e tried and couldn鈥檛 reproduce
In which android version did you try?

What about this little validation?

async getMediaStream(constraints): Promise<MediaStream> {
  return new Promise(function (resolve, reject) {
    if (navigator.mediaDevices
      && navigator.mediaDevices.getUserMedia) {
        navigator.mediaDevices.getUserMedia(constraints)
        .then((stream) => resolve(stream))
        .catch(err => reject(err));
    } else {
      const getUserMedia = navigator.getUserMedia
      || navigator['webkitGetUserMedia']
      || navigator['mozGetUserMedia']
      || navigator['msGetUserMedia'];
      getUserMedia(
        constraints,
        (stream) => resolve(stream),
        (err) => reject(err)
      );
    }
  });
}


getMediaStream({
  audio: isEdge ? true : {
    echoCancellation: false
  }
})
.then(stream => console.log(stream))
.catch(err => console.error(err))
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ebk46 picture ebk46  路  3Comments

nicobytes picture nicobytes  路  3Comments

mlynch picture mlynch  路  3Comments

stripathix picture stripathix  路  3Comments

stripathix picture stripathix  路  3Comments