html5 file调用手机摄像头

在切图网一个客户的webapp项目中需要用到 html5调用手机摄像头,找了很多资料,大都是 js调用api  然后怎样怎样,做了几个demo测试发现根本不行, 后来恍然大悟,用html5自带的 input file=""  ,纯html5,并且不涉及到js ,就可以实现。代码如下:


(亲测可用)html5调用手机摄像头




html 代码效果预览





123
    <input type="file" accept="image/*" capture="camera">
    <input type="file" accept="video/*" capture="camcorder">
    <input type="file" accept="audio/*" capture="microphone">








capture表示,可以捕获到系统默认的设备,比如:camera--照相机;camcorder--摄像机;microphone--录音。
accept表示,直接打开系统文件目录。


其实html5的input:file标签还支持一个multiple属性,表示可以支持多选,如:


html 代码效果预览





1
    <input type="file" accept="image/*" multiple>






加上这个multiple后,capture就没啥用了,因为multiple是专门yong用来支持多选的。


内容切图社区(qietu.cn) 首发,注明来源可转载。

http://www.qdfuns.com/notes/26716/2d4fea81a990f8532ce7fa43af286add.html

限制只能选择图片

[html] view plain copy
 
 
 
 
  1. <input type="file" accept="image/*">  


限制只能选择视频

[html] view plain copy
 
 
 
 
  1. <input type="file" accept="video/*">  

限制只能选择音频

[html] view plain copy
 
 
 
 
  1. <input type="file" accept="audio/*">  

直接打开摄像头拍照

[html] view plain copy
 
 
 
 
  1. <input type="file" accept="image/*" capture="camera">  


直接打开摄像头录像

[html] view plain copy
 
 
 
 
  1. <input type="file" accept="video/*" capture="camera"
原文地址:https://www.cnblogs.com/zoujinhua/p/12786391.html