简体   繁体   中英

getUserMedia Android Webview Ionic

I'm trying to do some basic things by getting an Android device's camera stream with getUserMedia. To my understanding, this should be supported on Android Lollipop, which I'm running, but even with permissions set to allow video and audio my request for a media stream is automatically denied.

So I tried using Crosswalk with Ionic, and I can get the media stream. The data is just empty. To my understanding this should be supported. Does anyone else have experience with getting camera video stream data with Cordova / Ionic?

Make sure that you have RECORD_AUDIO and CAMERA permissions in platforms/android/AndroidManifest.xml:

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

Cordova takes care about necessary permissions for Cordova API and adds them into manifest file, but it doesn't for HTML5 API.

The accepted answer definitely would have worked prior to the changes to Android permissions. You are now able to request usage of native functions at the time of use (which honestly makes more sense than on launch) so I highly recommend using the Android Permissions plugin which will allow you to check and request permissions programmatically and on demand.

For the same use case that is in the accepted answer you would do the following:

var permissions = cordova.plugins.permissions;

var permList = [
  permissions.CAMERA,
  permissions.RECORD_AUDIO
];

permissions.requestPermissions(permList, permCallBackSuccess, permCallBackError);

I hope this helps somebody down the road as it saved me a bunch of time!

The problem was fixed by the https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-audioCapture

$ cordova plugin add cordova-plugin-chrome-apps-audiocapture --save
$ cordova build
$ cordova run android

Now the microphone stream can be processed with the audioContext.createScriptProcessor .

ps. It seems, that for this feature to work, just the RECORD_AUDIO permission is not enough, the plugin uses also MODIFY_AUDIO_SETTINGS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM