親測可用)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"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM