- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to print the Camera Input to a Canvas Element in HTML5. On the desktop it works fine, but building it for Android devices with cordova, I cannot access the camera and I really don't know what I do wrong. I also tried it with Crosswalk, there I get no error, but the Camera isn't shown either. But i want to do it with Cordova.
Here is my Code:
navigator.getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia); navigator.getUserMedia(options, onSuccess, onFail); var options = { audio: false, video: { mandatory: { maxWidth: window.innerWidth, maxHeight: window.innerHeight }, optional: [{ facingMode: "user" }] } } var onFail = function(e) { alert('Failed to get camera'); }; var onSuccess = function(stream) { var video = document.getElementById('my-webcam'); if(navigator.mozGetUserMedia) { video.mozSrcObject = stream; console.log("videoWidth" + video.width); } else { var url = window.URL || window.webkitURL; video.src = url.createObjectURL(stream); } // Wait 1000 ms before starting the loop otherwise the videosize aren´t set, so the Canvas can´t get values from the video setTimeout(function(){ setInterval(updateCanvas,30); //manipulating the canvas here // Make sure the canvas is the same size as the video var video = document.getElementById('my-webcam'); //invisible var canvas = document.getElementById('my-canvas'); //where the camera input should be shown canvas.width = video.videoWidth; canvas.height = video.videoHeight; //- $('#mainPage_ButtonPhoto').height(); },1000); };
But if I build this, I always get the onfail alert "Failed to get camera".
I figured out it is a "errorPermissionDeniedError". I build it with xdk. But with this android.json, or app manifest for building android it is still not working and i still got the error. Here my android.json :
{ "prepare_queue": { "installed": [], "uninstalled": [] }, "config_munge": { "files": {} }, "installed_plugins": {}, "dependent_plugins": {}, "permissions": { "audio-capture": { "description": "Required to capture audio using getUserMedia()", access: "readwrite" }, "video-capture": { "description": "Required to capture video using getUserMedia()", access: "readwrite" } } }
Thank you very much for your help.
Kind regards,
SirSandmann
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The webview that your app runs inside does not have direct access to the camera, the way you specify such permissions are a function of the native platform and are usually handled by a plugin. What you are trying to do will probably only work with Crosswalk (which is Cordova, just Cordova with a better webview), but I'm not clear on if their is more that has to be done to get it working with Crosswalk.
Don't have any good suggestions, have not seen anyone try to do this in the context of a Cordova app. I recommend you search for Cordova or PhoneGap solutions to using this technique for hints on how to make this work. The alternative is to use some Cordova plugins that provide access to the camera and write it using one of those APIs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, thank you so far.
I was just wondering. Already tried everything and the mediaStream should be supported by Crosswalk (https://crosswalk-project.org/documentation/apis/web_apis.html). Tried phonegap plugins (Camera2Canvas) but still nothing. I will try my luck in an Crosswalk/Cordova forum.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm suspecting some Android permissions need to be set to get it working in the Crosswalk webview.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey Dan,
yes, i solved this one.
I just tried to give the device other permissions, because obviously these weren´t enough.
Here The List of Plugins I used in the Project:
I honestly forgot which one was the Plugin I added for adding the Permission. (If youi add the Plugins, some Permissions are set automatically and one/some of them were the right one). The App is working on my Phone, after I added the other for my project needed Plugins. Hope i could help, kind regards, Flo

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page