(亲测可用)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://blog.csdn.net/ty497122758/article/details/51813324

  • 6
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 15
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值