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)
}
},
9***@qq.com
- 发布:2024-05-12 11:52
- 更新:2024-05-12 11:52
- 阅读:283
0 个回复