I need to show 2 videos capturing from 2 different cameras attached to my laptop. One is my laptop camera and other one is attached USB webcam. I have tried with below code but both videos are coming from same camera but not different. Below my code. Can anyone help me to sort this please? TIA
<video id="cameraModule1" width="100%" height="100%" autoplay></video>
<video id="cameraModule2" width="100%" height="100%" autoplay></video>
<script>
//Selector for your <video> element
const cam1 = document.querySelector('#cameraModule1');
//Core
window.navigator.mediaDevices.getUserMedia({ video: true })
.then(stream => {
cam1.srcObject = stream;
cam1.onloadedmetadata = (e) => {
cam1.play();
};
})
.catch( () => {
alert('You have give browser the permission to run Webcam and mic ;( ');
});
</script>
<script>
//Selector for your <video> element
const cam2 = document.querySelector('#cameraModule2');
//Core
window.navigator.mediaDevices.getUserMedia({ video: true })
.then(stream => {
cam2.srcObject = stream;
cam2.onloadedmetadata = (e) => {
cam2.play();
};
})
.catch( () => {
alert('You have give browser the permission to run Webcam and mic ;( ');
});
</script>