9***@qq.com
9***@qq.com
  • 发布:2024-05-12 11:52
  • 更新:2024-05-12 11:52
  • 阅读:283

vue项目用h5+打包后,getUserMedia获取摄像头失败

分类:HTML5+
h5+
        init(){  
            return new Promise((resolve,reject)=>{  
                let constraints = { video: { facingMode: this.front ? "user" : "environment" } , audio: false }  
                this.getUserMedia(constraints,  
                    (MediaStream) => {  
                        this.localStream=MediaStream  
                        this.localVideo.srcObject=MediaStream  
                        this.localVideo.autoplay = true  
                        this.localVideo.play()  
                        console.log("====获取流数据====")  
                    },  
                    function (e) {  
                        console.log("获取流数据失败",e)  
                    }  
                )  
            })  
        },  
        getUserMedia (constrains, success, error) {  
            if (navigator.mediaDevices.getUserMedia) {  
                //最新标准API  
                navigator.mediaDevices.getUserMedia(constrains).then(success).catch(error)  
            } else if (navigator.webkitGetUserMedia) {  
                //webkit内核浏览器  
                navigator.webkitGetUserMedia(constrains).then(success).catch(error)  
            } else if (navigator.mozGetUserMedia) {  
                //Firefox浏览器  
                // eslint-disable-next-line no-undef  
                navigator.mozGetUserMedia(constrains).then(success).catch(error)  
            } else if (navigator.getUserMedia) {  
                //旧版API  
                navigator.getUserMedia(constrains).then(success).catch(error)  
            }  
        },  
2024-05-12 11:52 负责人:无 分享
已邀请:

要回复问题请先登录注册