Hi vishva,
You need to set the facingMode property of constraints.
facingMode has two option.
environment - To access the rear camera.
user - To access the front camera. It is by default if not set.
HTML
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<u>Live Camera</u>
<br />
<div id="webcam"></div>
<br />
<input type="button" id="btnCapture" value="Capture" />
<input type="button" id="btnSwitch" value="Back" />
</td>
</tr>
<tr>
<td align="center"><u>Captured Picture</u><br />
<img id="imgCapture" />
</td>
</tr>
</table>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcamjs/1.0.26/webcam.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
InitCam('user');
$("#btnCapture").click(function () {
Webcam.snap(function (data_uri) {
$("#imgCapture")[0].src = data_uri;
});
});
$("#btnSwitch").click(function () {
$('#btnSwitch').val($('#btnSwitch').val() == 'Back' ? 'Front' : 'Back');
var mode = $('#btnSwitch').val() == 'Back' ? 'user' : 'environment';
InitCam(mode);
});
});
function InitCam(mode) {
Webcam.reset();
Webcam.set({
width: 320,
height: 240,
image_format: 'jpeg',
jpeg_quality: 90,
constraints: {
facingMode: mode
}
});
Webcam.attach('#webcam');
}
</script>
Demo