Skip to content

Commit ec78b65

Browse files
committed
代码回滚
1 parent 92a1f6c commit ec78b65

1 file changed

Lines changed: 16 additions & 29 deletions

File tree

‎userMedia.html‎

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
<body>
4242
<div class="wrapper">
43-
<button id="openCamera" title="开启摄像头">开启摄像头权限</button>
43+
<button id="openCamera" title="开启摄像头">`开启摄像头权限</button>
4444

4545
<video width="700px" height="390px" class="video" autoplay="autoplay"></video>
4646

@@ -61,39 +61,26 @@
6161

6262
// 开启摄像头
6363
openCamera.addEventListener("click", () => {
64-
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator
65-
.mozGetUserMedia ||
66-
navigator.msGetUserMedia;
64+
navigator.getUserMedia = navigator.getUserMedia || navigator
65+
.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.mediaDevices.getUserMedia
6766

68-
if (!navigator.getUserMedia) return alert(
69-
'Native device media streaming (getUserMedia) not supported in this browser.');
67+
if (navigator.getUserMedia) {
7068

71-
if (this.isOpenCamera) return console.log('[已经开启过摄像头的权限了]');
69+
if (this.isOpenCamera) return console.log('[已经开启过摄像头的权限了]');
7270

7371

74-
let exArray = getSources()
75-
const constraints = {
76-
'video': {
77-
'optional': [{
78-
'sourceId': exArray[0] //0为前置摄像头,1为后置
79-
}]
80-
},
81-
'audio': true
72+
let exArray = getSources()
73+
navigator.getUserMedia({
74+
'video': {
75+
'optional': [{
76+
'sourceId': exArray[0] //0为前置摄像头,1为后置
77+
}]
78+
},
79+
'audio': true
80+
}, successFunc, errorFunc); //success是获取成功的回调函数
81+
} else {
82+
return alert('不支持访问用户媒体')
8283
}
83-
// navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
84-
// successFunc(stream)
85-
86-
// }).catch(function (err) {
87-
// alert(err.name + ": " + err.message);
88-
// }); // 总是在最后检查错误;
89-
navigator.getUserMedia({
90-
'video': {
91-
'optional': [{
92-
'sourceId': exArray[0] //0为前置摄像头,1为后置
93-
}]
94-
},
95-
'audio': true
96-
}, successFunc, errorFunc); //success是获取成功的回调函数
9784
})
9885

9986
// 摄像机成功回调

0 commit comments

Comments
 (0)