公众号h5页面使用navigator.mediaDevices.getUserMedia调用摄像头?
iOS17以下微信浏览器调用navigator.mediaDevices.getUserMedia授权之后调取不了摄像头,Safari浏览器可以,Android微信浏览器也可以 部分代码如下 <video ref="video" id="video" objectFit="cover" class="video-image" :controls="false" :show-center-play-btn="false" :autoplay="true" :loop="true" playsinline :webkit-playsinline="true"></video> <canvas ref="canvas" :style="canvasStyle" canvas-id="myCanvas" id="myCanvas"></canvas> init(options) { let error = '' try { this.video = document.querySelector('#video').children[0].children[0] // console.log("this.vide",this.video); // 前置摄像头 if ('mediaDevices' in window.navigator && 'getUserMedia' in window.navigator.mediaDevices) { // 浏览器支持 window.navigator.mediaDevices.getUserMedia({ 'video': true }).then((stream)=> { this.video.srcObject = stream // this.myVideo.play() this.initTracker(options) // console.log('getUserMedia completed successfully.'); }) .catch((error)=> { console.log(error.name + ": " + error.message); this.ArtificialTracker(error.message) }); } else { error = '手机不支持自动获取人脸' this.ArtificialTracker(error) } } catch (err) { this.ArtificialTracker(err.message) } },