| var exec = require('cordova/exec'), |
| MediaFile = require('cordova/plugin/MediaFile'); |
| |
| /** |
| * Launches a capture of different types. |
| * |
| * @param (DOMString} type |
| * @param {Function} successCB |
| * @param {Function} errorCB |
| * @param {CaptureVideoOptions} options |
| */ |
| function _capture(type, successCallback, errorCallback, options) { |
| var win = function(pluginResult) { |
| var mediaFiles = []; |
| var i; |
| for (i = 0; i < pluginResult.length; i++) { |
| var mediaFile = new MediaFile(); |
| mediaFile.name = pluginResult[i].name; |
| mediaFile.fullPath = pluginResult[i].fullPath; |
| mediaFile.type = pluginResult[i].type; |
| mediaFile.lastModifiedDate = pluginResult[i].lastModifiedDate; |
| mediaFile.size = pluginResult[i].size; |
| mediaFiles.push(mediaFile); |
| } |
| successCallback(mediaFiles); |
| }; |
| exec(win, errorCallback, "Capture", type, [options]); |
| } |
| /** |
| * The Capture interface exposes an interface to the camera and microphone of the hosting device. |
| */ |
| function Capture() { |
| this.supportedAudioModes = []; |
| this.supportedImageModes = []; |
| this.supportedVideoModes = []; |
| } |
| |
| /** |
| * Launch audio recorder application for recording audio clip(s). |
| * |
| * @param {Function} successCB |
| * @param {Function} errorCB |
| * @param {CaptureAudioOptions} options |
| */ |
| Capture.prototype.captureAudio = function(successCallback, errorCallback, options){ |
| _capture("captureAudio", successCallback, errorCallback, options); |
| }; |
| |
| /** |
| * Launch camera application for taking image(s). |
| * |
| * @param {Function} successCB |
| * @param {Function} errorCB |
| * @param {CaptureImageOptions} options |
| */ |
| Capture.prototype.captureImage = function(successCallback, errorCallback, options){ |
| _capture("captureImage", successCallback, errorCallback, options); |
| }; |
| |
| /** |
| * Launch device camera application for recording video(s). |
| * |
| * @param {Function} successCB |
| * @param {Function} errorCB |
| * @param {CaptureVideoOptions} options |
| */ |
| Capture.prototype.captureVideo = function(successCallback, errorCallback, options){ |
| _capture("captureVideo", successCallback, errorCallback, options); |
| }; |
| |
| |
| module.exports = new Capture(); |