getUserMedia() is crashing the app

When we call navigator.mediaDevices.getUserMedia({audio: true, video: {facingMode: ‘user’} to get a stream from the camera our app crashes and the promise doesn’t resolve (not going into then nor catch block). This is only happening on Android, and is working fine on Web and also when we open the web app in a chrome browser on the Android phone.


Here is a screenshot of the crash report in Android Studio but the error is pretty misleading. I tried googling the error and also everything I could think about but without any luck.

I also tried to build this poc from jceasarmobile to test if there is a problem with getUserMedia on a WebView but that worked without a problem.

I also would like to mention that we have a working prod version in play store that was build 2 months ago and the code for viewing camera and recording wasn’t changed at all.

I’m using Android Studio Bumblebee Patch 3, Capacitor Android 3.3.4 and tested on multiple devices. I tried to run and check the logs (which were the same) on Xiaomi Pocophone F1 running Android 10, and Google Pixel 6 running Android 12.

I can provide more info if needed, currently I’m working on creating a sample app with only getUserMedia to see if I can reproduce the issue there.

Thank you for the help in advance!

Do you have this permissions set in the AndroidManifest.xml?

     <!-- Navigator.getUserMedia -->
    <!-- Video -->
    <uses-permission android:name="android.permission.CAMERA" />
    <!-- Audio -->
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

I had the permissions, that wasn’t the problem. This was working before and just stopped working this past month. However I found the fix, the problem was in BridgeWebCustomClient.java where I added this code

@Override
public Bitmap getDefaultVideoPoster() {
    if (super.getDefaultVideoPoster() == null) {
        return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
    } else {
        return super.getDefaultVideoPoster();
    }
}

on line 84 and it fixed the error. The problem wasn’t really in getUserMedia() as we thought but because it couldn’t find bitmap poster once you started the recording. So if there is no defaultVideoPoster I’m setting a black square which fixes the problem. This seams like a capacitor problem with transparent bitmap png they had in the project.