访问摄像头没有Flash [英] Access webcam without Flash

查看:151
本文介绍了访问摄像头没有Flash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用HTML 5元素和JavaScript创建视频聊天应用程序,我不想使用Flash访问用户的网络摄像头。

I want to create a video chat application using HTML 5 elements and JavaScript, and I don't want to use Flash to access the user's webcams.

怎么能我只使用HTML和JavaScript实现了这个目标吗?

How can I accomplish this using only HTML and JavaScript?

推荐答案

在撰写本文时,最佳解决方案是WebRTC。 Chrome,Mozilla和Opera支持 ,但在Internet Explorer和Safari中仍然无法使用。

At the moment of writing this the best solution is WebRTC. It is supported in Chrome, Mozilla and Opera, but still unavaialble in Internet Explorer and Safari.

简约演示。

Index.html

<!DOCTYPE html>
<head>
</head>
<body>
    <video></video>
    <script src="webcam.js"></script>
</body>

webcam.js

(function () {
    navigator.getMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia);

    navigator.getMedia(
        // constraints
        {video:true, audio:false},

        // success callback
        function (mediaStream) {
            var video = document.getElementsByTagName('video')[0];
            video.src = window.URL.createObjectURL(mediaStream);
            video.play();
        },   
        //handle error
        function (error) {
            console.log(error);
        })   
})();

了解更多 here there

这篇关于访问摄像头没有Flash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆