doufocheng6233 2018-12-19 02:58
浏览 65

PHP - 显示移动相机以捕获QR码

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();
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题