How can I check if user has a webcam or not? [closed]

狂风中的少年 提交于 2019-11-29 02:47:07

There is a plugin:

http://www.xarg.org/project/jquery-webcam-plugin/

if(webcam.getCameraList().length == 0){  
   alert('You don\'t have a web camera');  
}
if(confirm('Do you have a webcam?')) {
    //they said yes :-)
} else {
    //they said no :-(
}

Muhammet was right. First need to add the plugin http://www.xarg.org/project/jquery-webcam-plugin/ Then you'll need to start the plugin:

$("#camera").webcam({
            width: 320,
            height: 240,
            mode: "callback",
            swffile: "/lorran/jscam_canvas_only.swf",
            onTick: function() {},
            onSave: function() {},
            onCapture: function() {},
            debug: function() {},
            onLoad: function() {}
        });

Then you add the script that check if user has a webcam.

var test;
        test = function(){
            var tester = false;
            try{
                if(webcam.getCameraList().length == 0){  
                   alert('You dont have a camera');  
                                            return;
                }else{
                    alert("cam");
                                            return;

                }
                tester = true;
            }catch(e){
                tester = false;
                setTimeout(test,1000);
            }
        }
        setTimeout(test,1000);

This try and catch is needed for the flash that have a delay to start, so you need to keep trying till the method webcam.getCameraList() exist.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!