User Tools

Site Tools


script-capture-download-delete

Capture - Download - Delete example

This example executes the following steps:

  1. Connect the script to the currently connected camera.
  2. Start recording.
  3. Wait for recording to finish.
  4. Get list of media from the camera.
  5. Download the latest media item from the camera. The media is automatically deleted from the camera when the download succeeds.
// Use the currently connected camera:
var connectResult = connectToCamera();
if (connectResult.ok) {
    var cameraName = connectResult.message;
 
    // Capture
    var result = startRecording(cameraName);
    if (!result.ok) {
        logMessage("Error capturing: " + result.message, true);
        return;
    }
 
    // Wait until capturing has finished
    result = waitForCameraRecordingState(cameraName, 0, "idle");
 
    // Load the media list from the camera
    var mediaList = getMediaList(cameraName, true);
 
    // Download the last media item
    // Media items are sorted by date (descending), thus we use the first one.
    // After download the media item is deleted.
    if (mediaList.length > 0) {
        var result = downloadMedia(cameraName, mediaList[0].mediaKey, "", true, false);
        if (!result.ok) {
            logMessage("Download error: " + result.message, true);
        }
    }
}
else logMessage("No camera found");
script-capture-download-delete.txt · Last modified: 2018/03/30 16:59 by teq