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" />).
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 allowDOMException: 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))
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.