HTML5:相机访问

发布于 2025-01-08 09:57:49 字数 1919 浏览 3 评论 0原文

我对 HTML5 还很陌生。我尝试使用以下 HTML5 代码来访问手机上的相机。它始终显示“不支持本机网络摄像头”。看来我的移动浏览器(safari 和 android 2.1 网络浏览器)不支持相机。

您能告诉我应该使用哪个浏览器来访问相机吗?

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, maximum-scale=1.0">
    <style>
        body {width: 100%;}
        canvas {display: none;}
    </style>
    <script>
        var video, canvas, msg;
        var load = function () {
            video  = document.getElementById('video');
            canvas = document.getElementById('canvas');
            msg    = document.getElementById('error');
            if( navigator.getUserMedia ) {
                video.onclick = function () {
                    var context = canvas.getContext("2d");
                    context.drawImage(video, 0, 0, 240, 320);
                    var image = {"demo" : {
                        "type"  : "device",
                        "image" : canvas.toDataURL("image/png")
                    }};
                };

                var success = function ( stream ) {
                    video.src = stream;
                };

                var error = function ( err ) {
                    msg.innerHTML = "Error: " + err.code;
                };

                navigator.getUserMedia('video', success, error);

            } else {
                msg.innerHTML = "Native web camera not supported :(";
            }

        };

        window.addEventListener('DOMContentLoaded', load, false);
    </script>
</head>
<body>
    <video  id="video" width="240" height="320" autoplay> </video>
    <p      id="error">Click on the video to send a snapshot to the receiving screen</p>
    <canvas id="canvas" width="240" height="320"> </canvas>
</body>
</html>

I am quite new to HTML5. I try the following HTML5 code to access camera on my mobile phone. It always display "Native web camera not supported". It seems that my mobile browser (safari and android 2.1 web browser) does not support the camera.

Could you please tell me which browser should I use to access to camera?

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, maximum-scale=1.0">
    <style>
        body {width: 100%;}
        canvas {display: none;}
    </style>
    <script>
        var video, canvas, msg;
        var load = function () {
            video  = document.getElementById('video');
            canvas = document.getElementById('canvas');
            msg    = document.getElementById('error');
            if( navigator.getUserMedia ) {
                video.onclick = function () {
                    var context = canvas.getContext("2d");
                    context.drawImage(video, 0, 0, 240, 320);
                    var image = {"demo" : {
                        "type"  : "device",
                        "image" : canvas.toDataURL("image/png")
                    }};
                };

                var success = function ( stream ) {
                    video.src = stream;
                };

                var error = function ( err ) {
                    msg.innerHTML = "Error: " + err.code;
                };

                navigator.getUserMedia('video', success, error);

            } else {
                msg.innerHTML = "Native web camera not supported :(";
            }

        };

        window.addEventListener('DOMContentLoaded', load, false);
    </script>
</head>
<body>
    <video  id="video" width="240" height="320" autoplay> </video>
    <p      id="error">Click on the video to send a snapshot to the receiving screen</p>
    <canvas id="canvas" width="240" height="320"> </canvas>
</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

风吹过旳痕迹 2025-01-15 09:57:49

Firefox 17+、Chrome 23+ 和 Opera 12+ 现在支持 getUserMedia 方法。 (请参阅 caniuse.com

CanIUse.com 支持网格截至 2012 年 2 月 24 日的屏幕截图

The getUserMedia method is now supported on Firefox 17+,Chrome 23+ and Opera 12+. (See caniuse.com)

Screenshot of the CanIUse.com support grid as of 2/24/12

盗琴音 2025-01-15 09:57:49

这适用于 Firefox 手机、Chrome 手机、iPhone 和 Android:

<input type="file" id="mypic" accept="image/*">

This works on Firefox mobile, Chrome mobile, iPhone and Android:

<input type="file" id="mypic" accept="image/*">
娜些时光,永不杰束 2025-01-15 09:57:49
<input type="file" accept="image/*;capture=camera">

请参阅捕获音频和音频HTML5 视频

支持:

  • Android 3.0 浏览器 - 最早的实现之一。观看此视频,了解其实际效果。
  • Android 版 Chrome (0.16)
  • 火狐移动版 10.0
  • iOS6 Safari 和 Chrome(部分支持)
<input type="file" accept="image/*;capture=camera">

See Capturing Audio & Video in HTML5

Support:

  • Android 3.0 browser - one of the first implementations. Check out this video to see it in action.
  • Chrome for Android (0.16)
  • Firefox Mobile 10.0
  • iOS6 Safari and Chrome (partial support)
┊风居住的梦幻卍 2025-01-15 09:57:49

我们通过网络拼凑而成的基本方法取得了一些成功:

<form method="post" action="takephoto.php" enctype="multipart/form-data">
<input type="file" accept="image/*" name="file">
<input type="submit">
</form>

然后在 PHP 文件中,我们使用 now() 或类似的存储方法生成唯一的文件名。

We've had some success with this basic approach cobbled together from across the Web:

<form method="post" action="takephoto.php" enctype="multipart/form-data">
<input type="file" accept="image/*" name="file">
<input type="submit">
</form>

Then in the PHP file we generate unique file names using now() or something similar for storage.

随梦而飞# 2025-01-15 09:57:49

我认为 Opera 是唯一支持此 HTML5 扩展的移动浏览器。

请参阅作者对此主题的注释;

http://francisshanahan.com/index.php/2011/stream-a-webcam-using-javascript-nodejs-android-opera-mobile-web-sockets-and-html5/

I think Opera is the only mobile browser that supports this HTML5 extension.

See note from the author to this thread;

http://francisshanahan.com/index.php/2011/stream-a-webcam-using-javascript-nodejs-android-opera-mobile-web-sockets-and-html5/

幸福还没到 2025-01-15 09:57:49

我最近刚刚开始使用一个名为 Bridgeit 的工具。

这是浏览器中的 JavaScript 和手机上的应用程序的组合。到目前为止似乎效果很好。

http://bridgeit.mobi/

I've just recently started working with a tool called Bridgeit.

This is a combination of javascript in the browser and an app on the phone. It seems to work pretty well so far.

http://bridgeit.mobi/

鸩远一方 2025-01-15 09:57:49

HTML5 添加了对相机访问的支持,您可以像这样使用它:


<输入类型=“文件”接受=“图像/*”捕获=“用户”>

其中 user 用于前置摄像头,environment 用于后置摄像头。

HTML5 added support for camera access, you can use it like this:

<input type="file" accept="image/*" capture>
<input type="file" accept="image/*" capture="user">
<input type="file" accept="image/*" capture="environment">

Where user is for front camera and environment is for back camera.

七秒鱼° 2025-01-15 09:57:49

Opera Desktop、Opera mobile 和 Chrome(更改一些配置后)目前支持 HTML5 摄像头/麦克风访问。

Opera Desktop, Opera mobile and Chrome (after changing some configuration) supports HTML5 camera / microphone access so far.

看春风乍起 2025-01-15 09:57:49

您可以通过启用 chrome://flags 下的“启用 WebRTC”标志来使用 Android 版 Chrome,

我在 Android 手机上测试过,可以访问 html5 页面上的摄像头,并且它可以正常工作。

You can use Chrome for Android by enabling the "Enable WebRTC" flag under chrome://flags

I tested on my android phone to access camera on html5 page and it's working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文