I attempted the given code above in an effort to record video in the background and save it to an SD card. I am looking for a way to automate the process without manually starting and stopping the recording. Can video be recorded using PhoneGap with or without an API? I specifically aim to record video in the background.
<html>
<head>
<title>Capture Video</title>
<script type="text/javascript" charset="utf-8" src="js/cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="js/json2.js"></script>
<script type="text/javascript" charset="utf-8">
// A button will call this function
function captureVideo() {
// Launch device video recording application,
// allowing user to capture up to 3 video clips
alert("captureVideo");
var options = {
limit : 2,
duration : 10
};
navigator.device.capture.captureVideo(captureSuccess, captureError,
options);
}
// Called when capture operation is finished
function captureSuccess(
mediaFiles) {
alert("captureSuccess ");
var i, len;
alert(mediaFiles.length);
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
}
// Called if something bad happens.
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, 'Uh oh!');
}
// Upload files to server
function uploadFile(mediaFile) {
alert("uploadFile");
var ft = new FileTransfer(), path = mediaFile.fullPath, name = mediaFile.name;
alert("path:" + path);
alert("name:" + name);
ft.upload(path, "http://my.domain.com/upload.php", function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
}, function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
}, {
fileName : name
});
}
</script>
</head>
<body>
<button onclick="captureVideo();">Capture Video</button>
<br>
</body>
</html>