【问题标题】:Why is HTML5 support for capturing camera in mobile browsers only?为什么 HTML5 仅支持在移动浏览器中捕获摄像头?
【发布时间】:2014-03-07 15:09:25
【问题描述】:

问题不在于为什么移动很重要,我明白这一点。

问题是,为什么还没有一个用于桌面的 HTML5 浏览器具有这些相同的获取用户媒体扩展??

基于this post

【问题讨论】:

  • 什么?您可以从桌面浏览器捕获相机。
  • here

标签: html camera getusermedia


【解决方案1】:

HTML

<video id="video" width="300" height="220" autoplay></video>
<button id="snap">Take Photo</button>
<canvas id="canvas" width="300" height="220"></canvas>

JS:

<Script>
    // Put event listeners into place
    window.addEventListener("DOMContentLoaded", function() {
        // Grab elements, create settings, etc.
        var canvas = document.getElementById("canvas"),
            context = canvas.getContext("2d"),
            video = document.getElementById("video"),
            videoObj = {
                "video": true
            },
            errBack = function(error) {
                console.log("Video capture error: ", error.code);
            };

        // Put video listeners into place
        if (navigator.getUserMedia) { // Standard
            navigator.getUserMedia(videoObj, function(stream) {
                video.src = stream;
                video.play();
            }, errBack);
        } else if (navigator.webkitGetUserMedia) { // WebKit-prefixed
            navigator.webkitGetUserMedia(videoObj, function(stream) {
                video.src = window.webkitURL.createObjectURL(stream);
                video.play();
            }, errBack);
        } else if (navigator.mozGetUserMedia) { // Firefox-prefixed
            navigator.mozGetUserMedia(videoObj, function(stream) {
                video.src = window.URL.createObjectURL(stream);
                video.play();
            }, errBack);
        }
        document.getElementById("snap").addEventListener("click", function() {
            context.drawImage(video, 0, 0, 300, 220);
        });
    }, false);
</Script>

适用于 chrome 和 firefox :)

【讨论】:

    【解决方案2】:

    Look at this link。本文档不完整。它会发生重大变化,虽然鼓励进行早期试验,但不打算实施。

    这就是为什么它不被浏览器完全支持的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-24
      • 2012-11-11
      • 1970-01-01
      • 2011-07-24
      • 1970-01-01
      • 2019-02-12
      相关资源
      最近更新 更多