Javascript 如何使用getUserMedia将后置摄像头添加到选项中?
我刚找到“说奶酪”JS,可以在网页中打开手机摄像头。Javascript 如何使用getUserMedia将后置摄像头添加到选项中?,javascript,html5-video,qr-code,smartphone,webcam-capture,Javascript,Html5 Video,Qr Code,Smartphone,Webcam Capture,我刚找到“说奶酪”JS,可以在网页中打开手机摄像头。 我的项目是用智能手机摄像头读取二维码,并将数据输入网站的输入字段 JS库工作得很好 我的问题是,代码只使用默认的摄像头(前),我还想使用后摄像头 如何实现此代码: 在此代码中: HTML选择 <!--SELECT CAMERA--> <select id="videoSource"> <option selected>Default Camera</option> </sele
我的项目是用智能手机摄像头读取二维码,并将数据输入网站的输入字段 JS库工作得很好 我的问题是,代码只使用默认的摄像头(前),我还想使用后摄像头 如何实现此代码:
在此代码中: HTML选择
<!--SELECT CAMERA-->
<select id="videoSource">
<option selected>Default Camera</option>
</select>
是不是在上面的代码中,我应该这样写:
function gotDevices(deviceInfos) {
for (var i = 0; i !== deviceInfos.length; ++i) {
var deviceInfo = deviceInfos[i];
var option = document.createElement('option');
option.value = deviceInfo.deviceId;
if (deviceInfo.kind === 'audioinput') {
option.text =
deviceInfo.label || 'microphone ' + (audioSelect.length + 1);
audioSelect.appendChild(option);
} else if (deviceInfo.kind === 'videoinput') {
option.text = deviceInfo.label || 'camera ' + (videoSelect.length + 1);
videoSelect.appendChild(option);
} else {
console.log('Found one other kind of source/device: ', deviceInfo);
}
}
}
正如你所说,我对JS了解不多。我正在使用Jquery来处理我需要的几乎所有东西
function gotDevices(deviceInfos) {
for (var i = 0; i !== deviceInfos.length; ++i) {
var deviceInfo = deviceInfos[i];
var option = document.createElement('option');
option.value = deviceInfo.deviceId;
if (deviceInfo.kind === 'audioinput') {
option.text =
deviceInfo.label || 'microphone ' + (audioSelect.length + 1);
audioSelect.appendChild(option);
} else if (deviceInfo.kind === 'videoinput') {
option.text = deviceInfo.label || 'camera ' + (videoSelect.length + 1);
videoSelect.appendChild(option);
} else {
console.log('Found one other kind of source/device: ', deviceInfo);
}
}
}