Jump to content

HTML5/JS Camera Access Mobile


SirSandmann
 Share

Recommended Posts

Hey Guys,
 

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.

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.

 

{    "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"      }    }}

Kind regards,
SirSandmann

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...