Camera API
Camera API provide the various functions to interact with camera. In order to use this API you have to add this permission to your package.json file.
android.permission.CAMERA
The following example shows how to init camera in your app
// In front process (web pages)
<html>
<head>
// add androidjs.js to get the API's of `Android JS`.
<script src = "./assets/ipc/androidjs.js" ></script>
</head>
<body>
<video id = "camera" autoplay></video>
</body>
<script>
window.onload = function(){
app.camera.init(document.getElementById('camera'), {video:true, audio: false});
}
</script>
</html>
Methods
app.camera.init(dom, options)
domis HTML dom, where you want to initialise camera.optionsis a JavaScript object, which define servicesvideoit could be justtrue/falseor an object{deviceId: {exact: devices[0]}}audioit could be justtrue/falseor an object{deviceId: {exact: devices[0]}}
An example of above code:
app.camera.init(document.getElementById('camera'), {video: true, audio: false});
app.camera.getDevices(callback)
callbackFunctiondevicesis list of video devices
Starts gathering information about all available video devices, and calls callback(devices) when finished.
An example of above code:
app.camera.getDevices(function(devices){
console.log(devices);
})
app.camera.startRecording(options)
optionsObjectmimeTypevideo type or codec (i.e.video/webm;codecs=vp9)bitsPerSecondbitrate (i.e.100000)
An example of above code:
app.camera.startRecording({mimeType: 'video/webm;codecs=vp9', bitsPerSecond: 100000});
app.camera.stopRecording()
An example of above code:
app.camera.stopRecording();
app.camera.saveRecording(filepath, filename, options)
filepathwhere you want to store the recorded video (i.e./storage/emulated/0/)filenamename of fileoptionsObjecttypevideo type (i.e.video/webm)
An example of above code:
app.camera.saveRecording('/storage/emulated/0/', 'newVideo1.webm', {type:'video/webm'})
app.camera.previewRecording(dom, options)
domwhere you want to preview the recorded videooptionsObjecttypevideo type (i.e.video/webm)
An example of above code:
// <video id = "preview" autoplay></video>
app.camera.previewRecording(document.getElementById('preview'), {type: 'video/webm'});
app.camera.getBuffer(options, callback)
callbackFunctionbuffer
optionsObjecttypevideo type (i.e.video/webm)
An example of above code:
app.camera.getBuffer({type: 'video/webm'}, function(buffer){
...
});
app.camera.takePhoto(cameraDom, previewDom)
cameraDomdom where the camera is already initialisedpreviewDomit is optional, if you want to preview the captured image provide the dom for preview otherwise none
An example of above code:
// <img id = "preview" autoplay></img>
app.camera.takePhoto(document.getElementById('camera'), document.getElementById('preview'));
app.camera.savePhoto(filepath, filename)
filepathwhere you want to store the captured photo (i.e./storage/emulated/0/)filenamename of file
An example of above code:
// <img id = "preview" autoplay></img>
app.camera.savePhoto('/storage/emulated/0/', 'test.webp');