目前浏览器拉起手机相机的有两种方式MediaDevices.getUserMedia()
和使用input
标签html
只要正确的配置accept
和capture
就能够打开手机相册,相机,麦克风android
<div>
<h2>camear</h2>
<input type="file" accept="image/*" capture="camera" />
<br />
<h2>camcorder</h2>
<input type="file" accept="video/*" capture="camcorder" />
<br />
<h2>microphone</h2>
<input type="file" accept="audio/*" capture="microphone" />
</div>
复制代码
注意踩坑ios
MediaDevices.getUserMedia()
能够调用相机和音频等,只是兼容性不太好,好比阿里的人脸识别若是支持 MediaDevices 就是用 MediaDevices 不支持就用 input 标签web
// 这里是MDN的小DEMO更多细节本身查阅吧
var constraints = { audio: true, video: { width: 1280, height: 720 } };
navigator.mediaDevices.getUserMedia(constraints)
.then(function(mediaStream) {
var video = document.querySelector('video');
video.srcObject = mediaStream;
video.onloadedmetadata = function(e) {
video.play();
};
})
复制代码
注意踩坑segmentfault