Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48978

MediaDevices.getUserMedia() permission denied in webview while camera is allowed

$
0
0

Hi everyone, I’m trying to use MediaDevices.getUserMedia() api in my webview app, but after a lot of effort I keep getting “permission denied” error even though camera access is allowed, here is what i added

app.module.ts

import { AndroidPermissions } from '@ionic-native/android-permissions/ngx';
...
providers: [    
AndroidPermissions,
]

app.component.ts

this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.CAMERA).then(
        result => console.log('Has permission?',result.hasPermission),
        err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.CAMERA)
      );
      
      this.androidPermissions.requestPermissions([this.androidPermissions.PERMISSION.CAMERA]);

config.xml

<plugin name="cordova-plugin-android-permissions" spec="1.1.2" />

AndroidManifest.xml

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

angular.json

"scripts": [
              "node_modules/webrtc-adapter/out/adapter.js"
            ]

In my web use api

function startVideo() {
     const constraints = { audio: false, video: { facingMode: "user" } }
     navigator.mediaDevices.getUserMedia(constraints)
     .then(function(mediaStream) {
     window.stream = mediaStream; 
     video.srcObject = mediaStream;
     video.onloadedmetadata = function(e) {
               video.play();
      };
     })
     .catch(function(err) { showAlert(err.name + ": " + err.message); });
}

It working on browser but not in my ionic app
Can anyone point out where I am missing?

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48978

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>