bensonruan / webcam-easy

javascript access webcam stream and take photo
https://bensonruan.com/how-to-access-webcam-and-take-photo-with-javascript
MIT License
241 stars 110 forks source link

How do I switch cameras? #14

Open chengkiang opened 3 years ago

chengkiang commented 3 years ago

If I have multiple webcams/video inputs, how do I specify which one to use? Right now, it defaults to the first one found.

pdivita commented 3 years ago

I had the same problem. Fixed adding a function to my local copy of webcam-easy.js Added this function:

set selectedDeviceId(value) {
    this._selectedDeviceId = value;
}

I call that function with the new id:

webcam.selectedDeviceId = otherWebcamDeviceId;
webcam.start();

Don't know if this is the cleanest solution (because the original variable was private probably for one reason) but works for me.