html5 打开摄像头

 

<video onloadedmetadata="" id="inputVideo" style="width: 1080px;height: 861.97px" autoplay muted playsinline></video>

 

<javascript>

const promise = navigator.mediaDevices.getUserMedia({ video: {} })

//获取异常 
promise.catch(function(MediaStream) {
  alert('摄像头未开启或浏览器无法打开摄像头')
  return
});
// 获取视频流
const stream = await navigator.mediaDevices.getUserMedia({ video: {} })
const videoEl = $('#inputVideo').get(0)
videoEl.srcObject = stream

</javascript>  

posted @ 2019-10-21 10:03  不知起什么名字  阅读(178)  评论(0编辑  收藏  举报