<div>
       <video id="video"   style="width=100%; height=100%; object-fit: fill" autoplay ref="videos"  v-show="showVideo"></video>           
       <canvas v-show="!showVideo"   width="300px" height="390px" id="personImgSize"></canvas>
 </div>

一进入这个页面就开始调用这个函数
在mouted中调用这个函数

    autoMakePhoto(){
            let canvas = document.getElementsByTagName('canvas')[0];
            this.context = canvas.getContext('2d');
            let _this=this;
            if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
                navigator.mediaDevices.getUserMedia({
                    video: true,
                }).then(function (stream) {
                    _this.MediaStreamTrack=typeof stream.stop==='function'?stream:stream.getTracks()[0];
                    let video = _this.$refs.videos;
                    video["srcObject"]=stream;
                    video.play();
                }).catch(function(err){
                    console.log(err);
                    //调用摄像头失败给的提示
                });
            }
        },

离开这个页面 关闭摄像头###

beforeDestroy(){
this.cancalCloseVideo();
}

methods:{
cancalCloseVideo(){
this.MediaStreamTrack && this.MediaStreamTrack.stop();
}
}

 

相关文章:

  • 2021-06-11
  • 2021-05-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案