Skip to content

Commit 963f4d6

Browse files
committed
摄像头切换
1 parent a591aec commit 963f4d6

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎main.js‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const videoElement = document.querySelector('video');
44
const audioInputSelect = document.querySelector('select#audioSource');
55
const audioOutputSelect = document.querySelector('select#audioOutput');
66
const videoSelect = document.querySelector('select#videoSource');
7-
const selectors = [audioInputSelect, audioOutputSelect, videoSelect];
7+
const selectors = [videoSelect];
88

99
let video = document.querySelector('video');
1010
let canvas = document.getElementById('canvas');
@@ -22,16 +22,13 @@ function gotDevices(deviceInfos) {
2222
}
2323
});
2424
for (let i = 0; i !== deviceInfos.length; ++i) {
25+
2526
const deviceInfo = deviceInfos[i];
2627
const option = document.createElement('option');
2728
option.value = deviceInfo.deviceId;
28-
if (deviceInfo.kind === 'audioinput') {
29-
option.text = deviceInfo.label || `microphone ${audioInputSelect.length + 1}`;
30-
audioInputSelect.appendChild(option);
31-
} else if (deviceInfo.kind === 'audiooutput') {
32-
option.text = deviceInfo.label || `speaker ${audioOutputSelect.length + 1}`;
33-
audioOutputSelect.appendChild(option);
34-
} else if (deviceInfo.kind === 'videoinput') {
29+
console.log('[deviceInfo.label]', deviceInfo.label);
30+
31+
if (deviceInfo.kind === 'videoinput') {
3532
option.text = deviceInfo.label || `camera ${videoSelect.length + 1}`;
3633
videoSelect.appendChild(option);
3734
} else {
@@ -45,7 +42,7 @@ function gotDevices(deviceInfos) {
4542
});
4643
}
4744

48-
navigator.mediaDevices.enumerateDevices().then(gotDevices).catch(handleError);
45+
navigator.mediaDevices.enumerateDevices().then(gotDevices)
4946

5047
// Attach audio output device to video element using device/sink ID.
5148
function attachSinkId(element, sinkId) {

‎userMedia.html‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@
6464

6565
<body>
6666
<div id="container">
67+
68+
<!-- <h1><a href="//webrtc.github.io/samples/" title="WebRTC samples homepage">WebRTC samples</a><span>Select sources
69+
&amp; outputs</span>
70+
</h1> -->
71+
72+
<!-- <div class="select">
73+
<label for="audioSource">Audio input source: </label><select id="audioSource"></select>
74+
</div> -->
75+
76+
<!-- <div class="select">
77+
<label for="audioOutput">Audio output destination: </label><select id="audioOutput"></select>
78+
</div> -->
79+
6780
<div class="select">
6881
<label for="videoSource">Video source: </label><select id="videoSource"></select>
6982
</div>

0 commit comments

Comments
 (0)