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)
dom
is HTML dom, where you want to initialise camera.options
is a JavaScript object, which define servicesvideo
it could be justtrue/false
or an object{deviceId: {exact: devices[0]}}
audio
it could be justtrue/false
or 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)
callback
Functiondevices
is 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)
options
ObjectmimeType
video type or codec (i.e.video/webm;codecs=vp9
)bitsPerSecond
bitrate (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)
filepath
where you want to store the recorded video (i.e./storage/emulated/0/
)filename
name of fileoptions
Objecttype
video 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)
dom
where you want to preview the recorded videooptions
Objecttype
video 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)
callback
Functionbuffer
options
Objecttype
video type (i.e.video/webm
)
An example of above code:
app.camera.getBuffer({type: 'video/webm'}, function(buffer){
...
});
app.camera.takePhoto(cameraDom, previewDom)
cameraDom
dom where the camera is already initialisedpreviewDom
it 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)
filepath
where you want to store the captured photo (i.e./storage/emulated/0/
)filename
name of file
An example of above code:
// <img id = "preview" autoplay></img>
app.camera.savePhoto('/storage/emulated/0/', 'test.webp');