我正在使用 webcam.js https://github.com/jhuckaby/webcamjs 在移动设备中,前置摄像头默认打开。我想将默认设置更改为后置摄像头。 有没有办法更换摄像头设备?
<script src="/js/webcamjs/webcam.js"></script>
<div id="my_camera" style="width:320px; height:240px;"></div>
<div id="my_result"></div>
<script language="JavaScript">
Webcam.set('constraints',{
facingMode: "environment"
});
Webcam.attach( '#my_camera' );
function take_snapshot() {
Webcam.snap( function(data_uri) {
document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/>';
} );
}
</script>
<a href="javascript:void(take_snapshot())">Take Snapshot</a>
var constraints = {
video: true,
facingMode: "environment"
};
在我的例子中,为了使其工作,我必须像这样声明相机设置:
Webcam.set({
width: 250,
height: 200,
image_format: 'jpeg',
jpeg_quality: 90,
// I add this object constraints
constraints: {
facingMode: 'environment'
}
});
var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); 如果(是移动设备){
Webcam.set({
width: 250,
height: 200,
image_format: 'jpg',
jpeg_quality: 90,
dest_width: 150,
dest_height: 150,
constraints: {
faceingMode:“环境”
}
});
}