为什么HTML5仅支持在移动浏览器中捕获相机?

时间:2014-03-07 15:09:26

标签: html5 camera getusermedia

问题不在于为什么移动设备很重要,我明白了。

问题是,如果桌面没有单一的HTML5浏览器具有这些相同的获取用户媒体扩展,那该怎么办呢?

基于this post

2 个答案:

答案 0 :(得分:0)

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:)

答案 1 :(得分:-1)

Look at this link。本文档不完整。它受到重大变化的影响,虽然鼓励早期试验,但它并不打算实施。

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