button.addEventListener('click', function (ev) {
console.log(mediaDevice.deviceId)
if (typeof currentStream !== 'undefined') {
stopMediaTracks(currentStream);
}
const videoConstraints = {};
console.log(mediaDevice.deviceId )
videoConstraints.deviceId = { exact: mediaDevice.deviceId };
const constraints = {
video: videoConstraints,
audio: true
};
navigator.mediaDevices
.getUserMedia(constraints)
.then(stream => {
currentStream = stream;
video.srcObject = stream;
return navigator.mediaDevices.enumerateDevices();
})
.then(gotDevices)
.catch(error => {
console.error(error);
});
})
摄像头切换
最新推荐文章于 2024-03-19 16:50:43 发布