Use getUserMedia in capacitor

Hello, I’m new in capacitor. I’m want to use navigator.getUserMedia in my capacitor app for android only and access the microphone through WebView as the PWA does on the android browser.
at the moment I’m getting undefind for navigator.getUserMedia and navigator.mediaDevices.

Is it possible? Any Demo project for that use
I have permissions for camera and audio recording.

1 Like

This is probably a stupid question, but you are running this on a real device with an actual microphone, right?

Yes, Samsung A72 with mic

Have you set the server.hostname or server.url variables in your Capacitor config? If you are, it disables the secure context of your application, and APIs like navigator.getUserMedia() won’t function.

1 Like

Didn’t touch those but I see on debug with android studio that the app is serve though http://192.168.41.0 should I try to change that?

1 Like

Problem solved. I added to capacitor.config.json

"server": {
		"hostname": "192.168.0.41:5000",
		"iosScheme": "https",
		"androidScheme": "https",
		"url": "https://192.168.0.41:5000"
	}

With the IP of my mobile phone
Also required permissions:

  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
  <uses-permission android:name="android.permission.RECORD_VIDEO"/>
  <uses-permission android:name="android.permission.RECORD_AUDIO"/>

if you need to use microphone or camera

Thank You @thomasvidas That’s was very helpfull

1 Like

You can always use this configuration in the capacitor.config.json file

server: {
    hostname: 'localhost',
    iosScheme: 'https',
    androidScheme: 'https'
  }

This will allow app to run on any IP and not on just static IP.
Permission are required depend on your app use.

1 Like

this works, thanks bro