webcamjs
webcamjs copied to clipboard
support camera select.
working in progress
- [x] flash mode
- [x] get user media
- [ ] ios
- [x] documents
notice
- it is not support for ios platform(for UA
/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream).
usage
checkout demos/choose-camera.html
demo
// register init event before `attach`, it will trigger when `getCameras` is valid.
Webcam.on("init", function () {
Webcam.getCameras(function (cameras) {
if (cameras.length > 0) {
Webcam.setAndInitCamera(cameras[cameras.length - 1].id);
}
});
});
Webcam.attach("#my_camera", true);
api
// getCameras return all reachable cameras. you should call it after `init` event.
Webcam.getCameras(function(data){
// data is array of camera objects.
// with id, label
// id: camera id, you should call setCamera with it
// label: camera name
});
// setAndInitCamera select camera via id(from getCameras method), and start camera.
Webcam.setAndInitCamera(id);
// initCamera start camera, it will use default camera if camera is not spcified.
// it is useful when you cannot find the camera you want.
Webcam.initCamera();