Closed Solbstr closed 2 years ago
it is a open source projet,you can fork and try something you want and pr it . 😀
Hi,
Thanks for this great library.
Is it possible to auto select the camera with best resolution?
maybe default is the best resolution. because it use browser API
it is a open source projet,you can fork and try something you want and pr it . 😀
Not sure if that's something I'm capable of, but thanks for the quick reply. 👍
What about doing something like this and adding constraints? It would also be great if the back camera is selected by default.
//----------------------------------------------------------------------
// Here we list all media devices, in order to choose between
// the front and the back camera.
// videoDevices[0] : Front Camera
// videoDevices[1] : Back Camera
// I used an array to save the devices ID
// which i get using devices.forEach()
// Then set the video resolution.
//----------------------------------------------------------------------
navigator.mediaDevices.enumerateDevices()
.then(devices => {
var videoDevices = [0,0];
var videoDeviceIndex = 0;
devices.forEach(function(device) {
console.log(device.kind + ": " + device.label +
" id = " + device.deviceId);
if (device.kind == "videoinput") {
videoDevices[videoDeviceIndex++] = device.deviceId;
}
});
var constraints = {width: { min: 1024, ideal: 1280, max: 1920 },
height: { min: 776, ideal: 720, max: 1080 },
deviceId: { exact: videoDevices[1] }
};
return navigator.mediaDevices.getUserMedia({ video: constraints });
})
.then(stream => {
if (window.webkitURL) {
video.src = window.webkitURL.createObjectURL(stream);
localMediaStream = stream;
} else if (video.mozSrcObject !== undefined) {
video.mozSrcObject = stream;
} else if (video.srcObject !== undefined) {
video.srcObject = stream;
} else {
video.src = stream;
}})
.catch(e => console.error(e));
Ref : https://stackoverflow.com/questions/16807133/select-the-camera-while-using-navigate-getusermedia
@densen2014 Is there a possibility to switch cameras if i have front and back camera?
yes. now is select the second camera. because first camera is font camera. but you can select camera what you want and automatically save your selected,for next time auto open and use it. try the demo website
i think i can not control the resolution,because the decode core is from zxing.js, i have another libs is for camera may be you can review and find some way to make it
This looks good. Is it using same library or another? if it is another, which one?
it just a camera,not decode barcode, script edit by myself, and is open source , you can fork and build it
Hi,
Thanks for this great library.
Is it possible to auto select the camera with best resolution?