0

I want to show the camera of my mobile on the form. but what i have for now is the camera is showing ONLY on web page of the Desktop not on the web page of the Mobile, why? why i cant access the camera of my mobile? please help thanks here is the code of the webcam.js

var WebCodeCamJS = function(element) {
'use strict';
this.Version = {
    name: 'WebCodeCamJS',
    version: '2.7.0',
    author: 'Tóth András',
};
var mediaDevices = window.navigator.mediaDevices;
mediaDevices.getUserMedia = function(c) {
    return new Promise(function(y, n) {
        (window.navigator.getUserMedia || window.navigator.mozGetUserMedia || window.navigator.webkitGetUserMedia).call(navigator, c, y, n);
    });
}
HTMLVideoElement.prototype.streamSrc = ('srcObject' in HTMLVideoElement.prototype) ? function(stream) {
    this.srcObject = !!stream ? stream : null;
} : function(stream) {
    if (!!stream) {
        this.src = (window.URL || window.webkitURL).createObjectURL(stream);
    } else {
        this.removeAttribute('src');
    }
};
var videoSelect, lastImageSrc, con, beepSound, w, h, lastCode;
var display = Q(element),
    DecodeWorker = null,
    video = html('<video muted autoplay playsinline></video>'),
    sucessLocalDecode = false,
    localImage = false,
    flipMode = [1, 3, 6, 8],
    isStreaming = false,
    delayBool = false,
    initialized = false,
    localStream = null,
    options = {
        decodeQRCodeRate: 5,
        decodeBarCodeRate: 3,
        successTimeout: 500,
        codeRepetition: true,
        tryVertical: true,
        frameRate: 15,
        width: 320,
        height: 240,
        constraints: {
            video: {
                mandatory: {
                    maxWidth: 1280,
                    maxHeight: 720
                },
                optional: [{
                    sourceId: true
                }]
            },
            audio: false,
        },
        flipVertical: false,
        flipHorizontal: false,
        zoom: 0,
        beep: 'audio/beep.mp3',
        decoderWorker: 'js/DecoderWorker.js',
        brightness: 0,
        autoBrightnessValue: 0,
        grayScale: 0,
        contrast: 0,
        threshold: 0,
        sharpness: [],
        resultFunction: function(res) {
            console.log(res.format + ": " + res.code);
        },
        cameraSuccess: function(stream) {
            console.log('cameraSuccess');
        },
        canPlayFunction: function() {
            console.log('canPlayFunction');
        },
        getDevicesError: function(error) {
            console.log(error);
        },
        getUserMediaError: function(error) {
            console.log(error);
        },
        cameraError: function(error) {
            console.log(error);
        }
    };

and here is my code of the Play which will trigger the button to show the camera

  function play() {
    if (!localImage) {
        if (!localStream) {
            init();
        }
        const p = video.play();
        if (p && (typeof Promise !== 'undefined') && (p instanceof Promise)) {
            p.catch(e => null);
        }
        delay();
    }
}
  • Is your mobile browser allowed to access the camera? Unless it is explicitly allowed to do so, the camera won't launch – Javier Larroulet Dec 19 '18 at 03:02
  • okay.. your point is i need to set something on the browser? i haven't done that yet on the browser of my mobile. im using google chrome i dont think i need to set up any browser .. but if i would how can i do that? –  Dec 19 '18 at 03:04
  • @JavierLarroulet how can i set it please help –  Dec 19 '18 at 03:20
  • check out https://stackoverflow.com/questions/6336641/camera-access-through-browser or https://stackoverflow.com/questions/32994643/html-5-browser-camera-permission or https://stackoverflow.com/questions/12024770/access-camera-from-a-browser – Sean Dec 19 '18 at 04:58

0 Answers0