快活林资源网 Design By www.csstdc.com

不支持IE浏览器(需要使用flash插件), 支持移动端, 未经过完全测试

PC端使用的时候, HTML页面需要预留video标签, canvas标签

移动端使用的时候, HTML页面需要预留file标签, canvas标签, img标签

(function (window, document) {
  window.camera = {
    init: function (options) {
      /**
       * options 属性示例
       * videoID: video控件ID
       * canvasID: canvas控件ID
       * fileID: type为file的input控件的ID
       * imageID: img控件的ID
       * videoEnable: 是否启用摄像头
       * audioEnable: 是否启用麦克风
       * videoWidth: 视频宽度
       * videoHeight: 视频高度
       * photoWidth: 拍照宽度
       * photoHeight: 拍照高度
       */

      _options = options;
      if (isMobileTerminal()) {
        initMobileTerminal();
      } else {
        initComputerTerminal();
      }
    },
    photo: function () {
      if (isMobileTerminal()) {
        photoMobileTerminal();
      } else {
        photoComputerTerminal();
      }
    }
  };

  let _options = null;

  function initComputerTerminal() {
    let videoDom = document.getElementById(_options.videoID);
    if (!videoDom) {
      alert('Video 控件无效');
      return;
    }

    let canvasDom = document.getElementById(_options.canvasID);
    if (!canvasDom) {
      alert('Canvas 控件无效');
      return;
    }
    canvasDom.setAttribute('width', _options.photoWidth + 'px');
    canvasDom.setAttribute('height', _options.photoHeight + 'px');

    let parameters = {
      video: _options.videoEnable "2d");
          context.drawImage(imageDom, 0, 0, _options.photoWidth, _options.photoHeight);
        }, 300);
      };
      reader.readAsDataURL(file);
    });
  }

  function photoMobileTerminal() {
    let fileDom = document.getElementById(_options.fileID);
    fileDom.click();
  }

  function isMobileTerminal() {
    if (/AppleWebKit.*Mobile/i.test(navigator.userAgent) || /Mobile/.test(navigator.userAgent) || /MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))
      return /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent);
    return false;
  }
})(window, document);

以上就是js调用网络摄像头的方法的详细内容,更多关于js调用网络摄像头的资料请关注其它相关文章!

快活林资源网 Design By www.csstdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
快活林资源网 Design By www.csstdc.com