androidjs

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)

An example of above code:

app.camera.init(document.getElementById('camera'), {video: true, audio: false});

app.camera.getDevices(callback)

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)

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)

An example of above code:

app.camera.saveRecording('/storage/emulated/0/', 'newVideo1.webm', {type:'video/webm'})

app.camera.previewRecording(dom, options)

An example of above code:

// <video id = "preview" autoplay></video>
app.camera.previewRecording(document.getElementById('preview'), {type: 'video/webm'});

app.camera.getBuffer(options, callback)

An example of above code:

app.camera.getBuffer({type: 'video/webm'}, function(buffer){
    ...
});

app.camera.takePhoto(cameraDom, previewDom)

An example of above code:

// <img id = "preview" autoplay></img>
app.camera.takePhoto(document.getElementById('camera'), document.getElementById('preview'));

app.camera.savePhoto(filepath, filename)

An example of above code:

// <img id = "preview" autoplay></img>
app.camera.savePhoto('/storage/emulated/0/', 'test.webp');