📅  最后修改于: 2022-03-11 15:00:32.809000             🧑  作者: Mango
navigator.mediaDevices.enumerateDevices()
.then(devices => {
var camera = devices.find(device => device.kind == "videoinput");
if (camera) {
var constraints = { deviceId: { exact: camera.deviceId } };
return navigator.mediaDevices.getUserMedia({ video: constraints });
}
})
.then(stream => video.srcObject = stream)
.catch(e => console.error(e));