input调用设备录像,相机等&helli p;
HT ML 5 官方 文档解释:capture属性用于调用设备的摄像头或 麦克风 。
当accept=]audio/或video/]时capture只有两种值,一种是user,用于调用面向人脸的摄像头(例如手机前置摄像头),一种是 env ironment,用于调用环境摄像头(例如手机后置摄像头)。
当accept=]audio]时,只要有capture就调用设备麦克风,忽略user和environment值。
至于网上提到的c am era和file Sys tem,官方没提。
官方文档: HdhCmsTestw3.org/TR/2018/REC-html-media-capture-20180201/
iOS最遵守遵守HTML5规范,其次是X5内核, 安卓 的webview基本忽略了capture。
理想 情况下 应该 按照如下开发webview:
1.当accept=]image/]时,capture=]user]调用前置照相机,capture=]其他值],调用后置照相机
2. 当accept=]video/]时,capture=]user]调用前置录像机,capture=]其他值],调用后置录像机
3. 当accept=]image/,video/],capture=]user]调用前置摄像头,capture=]其他值],调用后置摄像头,默认照相,可切换录像
4. 当accept=]audio/*]时,capture=]放空 或者 任意值],调用录音机
5. 当input没有capture时,根据accppt类型给出文件夹选项以及摄像头或者录音机选项
6. input含有multiple时访问文件夹可勾选多文件,调用系统摄像头或者录音机都只是单文件
7. 无multiple时都只能单文件
判断设备类型
VAR ua = navigator.userAgent.toLowerCase(); if(ua.match(/and ROI d/i)) == "android") { alert("android"); } if(ua.match(/iPhone/i)) == "iPhone") { alert("iPhone"); } if(ua.match(/iPad/i)) == "iPad") { alert("iPad"); }
<!DOCTY PE html> <html lang="en"> <head> < ;m eta charset="UTF-8"> <meta name="viewport" content="width=device-width, in IT ial -s cale=1.0"> <title>Document</title> </head> <body> <input type="file" accept="image/*" capture="camera"> <input type="file" accept="video/*" capture="camcorder"> <input type="file" accept="audio/*" capture="microphone"> </body> </html> <script> var file = document.querySelector('input'); if (getIos()) { file.removeAttribute("capture"); //如果是ios设备就删除"capture"属性 } function getIos() { var ua=navigator.userAgent.toLowerCase(); if (ua.match(/iPhone\sOS/i) == "iphone os") { return true; } else { return false; } } </script>
到此这篇关于Html5在手机端调用相机的方法实现的 文章 就介绍到这了,更多相关Html5手机端调用相机内容请搜索以前的文章或继续浏览下面的相关文章,希望大家以后多多支持!
总结
以上是 为你收集整理的 Html5在手机端调用相机的方法实现 全部内容,希望文章能够帮你解决 Html5在手机端调用相机的方法实现 所遇到的问题。
如果觉得 网站内容还不错, 推荐好友。
查看更多关于Html5在手机端调用相机的方法实现的详细内容...