' +
+ contentEl.innerHTML =
+ '
' +
'
Status: ' +
- 'img:
' +
+ 'img1:
' +
+ 'img2:
' +
+ 'img3:
' +
'video:
' +
'
' +
'Expected result: Audio recorder will come up. Press record button to record for 10 seconds. Press Done. Status box will update with audio file and automatically play recording.' +
'
' +
'Expected result: Status box will update with image just taken.' +
+ '
' +
+ 'Expected result: Status box will update with images just taken.' +
'
' +
'Expected result: Record 10 second video. Status box will update with video file that you can play.' +
'
' +
- 'Expected result: Record 5 second video. Status box will show that URL was resolved and video will get added at the bottom of the status box for playback.';
-
- createActionButton('Capture 10 sec of audio and play', function () {
- getAudio();
- }, 'audio');
-
- createActionButton('Capture 1 image', function () {
- getImage();
- }, 'image');
-
- createActionButton('Capture 10 sec of video', function () {
- getVideo();
- }, 'video');
-
- createActionButton('Capture 5 sec of video and resolve', function () {
- resolveVideo();
- }, 'video_and_resolve');
+ 'Expected result: Record 5 second video. Status box will show that URL was resolved and video will get added at the bottom of the status box for playback.' +
+ '
' +
+ 'Expected result (iOS only): camera picker and alert with message that camera access is prohibited are shown. The alert has 2 buttons: OK and Settings. By click on "OK" camera is hidden, by pressing Settings it shows privacy settings for the app' +
+ '
' +
+ 'Expected result (iOS only): camera picker and alert with message that camera access is prohibited are shown. The alert has 2 buttons: OK and Settings. By click on "OK" camera is hidden, by pressing Settings it shows privacy settings for the app';
+
+ createActionButton(
+ 'Capture 10 sec of audio and play',
+ function () {
+ getAudio();
+ },
+ 'audio'
+ );
+
+ createActionButton(
+ 'Capture 1 image',
+ function () {
+ getImage();
+ },
+ 'image'
+ );
+
+ createActionButton(
+ 'Capture 3 images',
+ function () {
+ getImages();
+ },
+ 'images'
+ );
+
+ createActionButton(
+ 'Capture 10 sec of video',
+ function () {
+ getVideo();
+ },
+ 'video'
+ );
+
+ createActionButton(
+ 'Capture 5 sec of video and resolve',
+ function () {
+ resolveVideo();
+ },
+ 'video_and_resolve'
+ );
+
+ createActionButton(
+ 'Disable access to Camera and click to capture video',
+ function () {
+ getVideoPermissionError();
+ },
+ 'prohibited_camera_video'
+ );
+
+ createActionButton(
+ 'Disable access to Camera and click to capture image',
+ function () {
+ getImagePermissionError();
+ },
+ 'prohibited_camera_image'
+ );
};
diff --git a/types/index.d.ts b/types/index.d.ts
new file mode 100644
index 00000000..17f53858
--- /dev/null
+++ b/types/index.d.ts
@@ -0,0 +1,168 @@
+// Type definitions for Apache Cordova MediaCapture plugin
+// Project: https://github.com/apache/cordova-plugin-media-capture
+// Definitions by: Microsoft Open Technologies Inc
+// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
+//
+// Copyright (c) Microsoft Open Technologies Inc
+// Licensed under the MIT license
+
+interface Navigator {
+ device: Device;
+}
+
+interface Device {
+ capture: Capture;
+}
+
+/** This plugin provides access to the device's audio, image, and video capture capabilities. */
+interface Capture {
+ /**
+ * Start the audio recorder application and return information about captured audio clip files.
+ * @param onSuccess Executes when the capture operation finishes with an array
+ * of MediaFile objects describing each captured audio clip file.
+ * @param onError Executes, if the user terminates the operation before an audio clip is captured,
+ * with a CaptureError object, featuring the CaptureError.CAPTURE_NO_MEDIA_FILES error code.
+ * @param options Encapsulates audio capture configuration options.
+ */
+ captureAudio(
+ onSuccess: (mediaFiles: MediaFile[]) => void,
+ onError: (error: CaptureError) => void,
+ options?: AudioOptions): void ;
+ /**
+ * Start the camera application and return information about captured image files.
+ * @param onSuccess Executes when the capture operation finishes with an array
+ * of MediaFile objects describing each captured image clip file.
+ * @param onError Executes, if the user terminates the operation before an audio clip is captured,
+ * with a CaptureError object, featuring the CaptureError.CAPTURE_NO_MEDIA_FILES error code.
+ * @param options Encapsulates audio capture configuration options.
+ */
+ captureImage(
+ onSuccess: (mediaFiles: MediaFile[]) => void,
+ onError: (error: CaptureError) => void,
+ options?: ImageOptions): void ;
+ /**
+ * Start the video recorder application and return information about captured video clip files.
+ * @param onSuccess Executes when the capture operation finishes with an array
+ * of MediaFile objects describing each captured video clip file.
+ * @param onError Executes, if the user terminates the operation before an audio clip is captured,
+ * with a CaptureError object, featuring the CaptureError.CAPTURE_NO_MEDIA_FILES error code.
+ * @param options Encapsulates audio capture configuration options.
+ */
+ captureVideo(
+ onSuccess: (mediaFiles: MediaFile[]) => void,
+ onError: (error: CaptureError) => void,
+ options?: VideoOptions): void ;
+ /** The audio recording formats supported by the device. */
+ supportedAudioModes: ConfigurationData[];
+ /** The recording image sizes and formats supported by the device. */
+ supportedImageModes: ConfigurationData[];
+ /** The recording video resolutions and formats supported by the device. */
+ supportedVideoModes: ConfigurationData[];
+}
+
+/** Encapsulates properties of a media capture file. */
+interface MediaFile {
+ /** The name of the file, without path information. */
+ name: string;
+ /** The full path of the file, including the name. */
+ fullPath: string;
+ /** The file's mime type */
+ type: string;
+ /** The date and time when the file was last modified. */
+ lastModifiedDate: Date;
+ /** The size of the file, in bytes. */
+ size: number;
+ /**
+ * Retrieves format information about the media capture file.
+ * @param successCallback Invoked with a MediaFileData object when successful.
+ * @param errorCallback Invoked if the attempt fails, this function.
+ */
+ getFormatData(
+ successCallback: (data: MediaFileData) => void,
+ errorCallback?: () => void): void;
+}
+
+/** Encapsulates format information about a media file. */
+interface MediaFileData {
+ /** The actual format of the audio and video content. */
+ codecs: string;
+ /** The average bitrate of the content. The value is zero for images. */
+ bitrate: number;
+ /** The height of the image or video in pixels. The value is zero for audio clips. */
+ height: number;
+ /** The width of the image or video in pixels. The value is zero for audio clips. */
+ width: number;
+ /** The length of the video or sound clip in seconds. The value is zero for images. */
+ duration: number;
+}
+
+/** Encapsulates the error code resulting from a failed media capture operation. */
+interface CaptureError {
+ /**
+ * One of the pre-defined error codes listed below.
+ * CaptureError.CAPTURE_INTERNAL_ERR
+ * The camera or microphone failed to capture image or sound.
+ * CaptureError.CAPTURE_APPLICATION_BUSY
+ * The camera or audio capture application is currently serving another capture request.
+ * CaptureError.CAPTURE_INVALID_ARGUMENT
+ * Invalid use of the API (e.g., the value of limit is less than one).
+ * CaptureError.CAPTURE_NO_MEDIA_FILES
+ * The user exits the camera or audio capture application before capturing anything.
+ * CaptureError.CAPTURE_NOT_SUPPORTED
+ * The requested capture operation is not supported.
+ */
+ code: number;
+ message: string;
+}
+
+declare var CaptureError: {
+ /** Constructor for CaptureError */
+ new (code: number, message: string): CaptureError;
+ CAPTURE_INTERNAL_ERR: number;
+ CAPTURE_APPLICATION_BUSY: number;
+ CAPTURE_INVALID_ARGUMENT: number;
+ CAPTURE_NO_MEDIA_FILES: number;
+ CAPTURE_NOT_SUPPORTED: number;
+ CAPTURE_PERMISSION_DENIED: number;
+}
+
+/** Encapsulates audio capture configuration options. */
+interface AudioOptions {
+ /**
+ * The maximum number of audio clips the device's user can capture in a single
+ * capture operation. The value must be greater than or equal to 1.
+ */
+ limit?: number;
+ /** The maximum duration of a audio clip, in seconds. */
+ duration?: number;
+}
+
+/** Encapsulates image capture configuration options. */
+interface ImageOptions {
+ /**
+ * The maximum number of images the user can capture in a single capture operation.
+ * The value must be greater than or equal to 1 (defaults to 1).
+ */
+ limit?: number;
+}
+
+/** Encapsulates video capture configuration options. */
+interface VideoOptions {
+ /**
+ * The maximum number of video clips the device's user can capture in a single
+ * capture operation. The value must be greater than or equal to 1.
+ */
+ limit?: number;
+ /** The maximum duration of a video clip, in seconds. */
+ duration?: number;
+}
+
+/** Encapsulates a set of media capture parameters that a device supports. */
+interface ConfigurationData {
+ /** The ASCII-encoded lowercase string representing the media type. */
+ type: string;
+ /** The height of the image or video in pixels. The value is zero for sound clips. */
+ height: number;
+ /** The width of the image or video in pixels. The value is zero for sound clips. */
+ width: number;
+}
\ No newline at end of file
diff --git a/www/CaptureAudioOptions.js b/www/CaptureAudioOptions.js
index b5f56051..65aad35b 100644
--- a/www/CaptureAudioOptions.js
+++ b/www/CaptureAudioOptions.js
@@ -17,12 +17,12 @@
* specific language governing permissions and limitations
* under the License.
*
-*/
+ */
/**
* Encapsulates all audio capture operation configuration options.
*/
-var CaptureAudioOptions = function(){
+var CaptureAudioOptions = function () {
// Upper limit of sound clips user can record. Value must be equal or greater than 1.
this.limit = 1;
// Maximum duration of a single sound clip in seconds.
diff --git a/www/CaptureError.js b/www/CaptureError.js
index 98927091..63c1997c 100644
--- a/www/CaptureError.js
+++ b/www/CaptureError.js
@@ -17,13 +17,13 @@
* specific language governing permissions and limitations
* under the License.
*
-*/
+ */
/**
* The CaptureError interface encapsulates all errors in the Capture API.
*/
-var CaptureError = function(c) {
- this.code = c || null;
+var CaptureError = function (c) {
+ this.code = c || null;
};
// Camera or microphone failed to capture image or sound.
diff --git a/www/CaptureImageOptions.js b/www/CaptureImageOptions.js
index 1fb5615e..869661fe 100644
--- a/www/CaptureImageOptions.js
+++ b/www/CaptureImageOptions.js
@@ -17,12 +17,12 @@
* specific language governing permissions and limitations
* under the License.
*
-*/
+ */
/**
* Encapsulates all image capture operation configuration options.
*/
-var CaptureImageOptions = function(){
+var CaptureImageOptions = function () {
// Upper limit of images user can take. Value must be equal or greater than 1.
this.limit = 1;
};
diff --git a/www/CaptureVideoOptions.js b/www/CaptureVideoOptions.js
index 261dbae8..6487174e 100644
--- a/www/CaptureVideoOptions.js
+++ b/www/CaptureVideoOptions.js
@@ -17,12 +17,12 @@
* specific language governing permissions and limitations
* under the License.
*
-*/
+ */
/**
* Encapsulates all video capture operation configuration options.
*/
-var CaptureVideoOptions = function(){
+var CaptureVideoOptions = function () {
// Upper limit of videos user can record. Value must be equal or greater than 1.
this.limit = 1;
// Maximum duration of a single video clip in seconds.
diff --git a/www/ConfigurationData.js b/www/ConfigurationData.js
index 57cfbf57..abaf4b39 100644
--- a/www/ConfigurationData.js
+++ b/www/ConfigurationData.js
@@ -17,12 +17,12 @@
* specific language governing permissions and limitations
* under the License.
*
-*/
+ */
/**
* Encapsulates a set of parameters that the capture device supports.
*/
-function ConfigurationData() {
+function ConfigurationData () {
// The ASCII-encoded string in lower case representing the media type.
this.type = null;
// The height attribute represents height of the image or video in pixels.
diff --git a/www/MediaFile.js b/www/MediaFile.js
index 1bc600ff..311386ed 100644
--- a/www/MediaFile.js
+++ b/www/MediaFile.js
@@ -17,12 +17,12 @@
* specific language governing permissions and limitations
* under the License.
*
-*/
+ */
-var utils = require('cordova/utils'),
- exec = require('cordova/exec'),
- File = require('cordova-plugin-file.File'),
- CaptureError = require('./CaptureError');
+var utils = require('cordova/utils');
+var exec = require('cordova/exec');
+var File = require('cordova-plugin-file.File');
+var CaptureError = require('./CaptureError');
/**
* Represents a single file.
*
@@ -32,7 +32,7 @@ var utils = require('cordova/utils'),
* lastModifiedDate {Date} last modified date
* size {Number} size of the file in bytes
*/
-var MediaFile = function(name, localURL, type, lastModifiedDate, size){
+var MediaFile = function (name, localURL, type, lastModifiedDate, size) {
MediaFile.__super__.constructor.apply(this, arguments);
};
@@ -44,11 +44,11 @@ utils.extend(MediaFile, File);
* @param {Function} successCB
* @param {Function} errorCB
*/
-MediaFile.prototype.getFormatData = function(successCallback, errorCallback) {
- if (typeof this.fullPath === "undefined" || this.fullPath === null) {
+MediaFile.prototype.getFormatData = function (successCallback, errorCallback) {
+ if (typeof this.fullPath === 'undefined' || this.fullPath === null) {
errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
} else {
- exec(successCallback, errorCallback, "Capture", "getFormatData", [this.localURL, this.type]);
+ exec(successCallback, errorCallback, 'Capture', 'getFormatData', [this.fullPath, this.type]);
}
};
diff --git a/www/MediaFileData.js b/www/MediaFileData.js
index 75e467b4..2031f6aa 100644
--- a/www/MediaFileData.js
+++ b/www/MediaFileData.js
@@ -17,7 +17,7 @@
* specific language governing permissions and limitations
* under the License.
*
-*/
+ */
/**
* MediaFileData encapsulates format information of a media file.
@@ -28,7 +28,7 @@
* @param {long} width
* @param {float} duration
*/
-var MediaFileData = function(codecs, bitrate, height, width, duration){
+var MediaFileData = function (codecs, bitrate, height, width, duration) {
this.codecs = codecs || null;
this.bitrate = bitrate || 0;
this.height = height || 0;
diff --git a/www/android/init.js b/www/android/init.js
index ace39e2e..928d0089 100644
--- a/www/android/init.js
+++ b/www/android/init.js
@@ -1,44 +1,44 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-var cordova = require('cordova'),
- helpers = require('./helpers');
-
-var SUCCESS_EVENT = "pendingcaptureresult";
-var FAILURE_EVENT = "pendingcaptureerror";
-
-var sChannel = cordova.addStickyDocumentEventHandler(SUCCESS_EVENT);
-var fChannel = cordova.addStickyDocumentEventHandler(FAILURE_EVENT);
-
-// We fire one of two events in the case where the activity gets killed while
-// the user is capturing audio, image, video, etc. in a separate activity
-document.addEventListener("deviceready", function() {
- document.addEventListener("resume", function(event) {
- if (event.pendingResult && event.pendingResult.pluginServiceName === "Capture") {
- if (event.pendingResult.pluginStatus === "OK") {
- var mediaFiles = helpers.wrapMediaFiles(event.pendingResult.result);
- sChannel.fire(mediaFiles);
- } else {
- fChannel.fire(event.pendingResult.result);
- }
- }
- });
-});
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+var cordova = require('cordova');
+var helpers = require('./helpers');
+
+var SUCCESS_EVENT = 'pendingcaptureresult';
+var FAILURE_EVENT = 'pendingcaptureerror';
+
+var sChannel = cordova.addStickyDocumentEventHandler(SUCCESS_EVENT);
+var fChannel = cordova.addStickyDocumentEventHandler(FAILURE_EVENT);
+
+// We fire one of two events in the case where the activity gets killed while
+// the user is capturing audio, image, video, etc. in a separate activity
+document.addEventListener('deviceready', function () {
+ document.addEventListener('resume', function (event) {
+ if (event.pendingResult && event.pendingResult.pluginServiceName === 'Capture') {
+ if (event.pendingResult.pluginStatus === 'OK') {
+ var mediaFiles = helpers.wrapMediaFiles(event.pendingResult.result);
+ sChannel.fire(mediaFiles);
+ } else {
+ fChannel.fire(event.pendingResult.result);
+ }
+ }
+ });
+});
diff --git a/www/capture.js b/www/capture.js
index 11c916b8..26b08ed3 100644
--- a/www/capture.js
+++ b/www/capture.js
@@ -17,10 +17,10 @@
* specific language governing permissions and limitations
* under the License.
*
-*/
+ */
-var exec = require('cordova/exec'),
- helpers = require('./helpers');
+var exec = require('cordova/exec');
+var helpers = require('./helpers');
/**
* Launches a capture of different types.
@@ -30,18 +30,17 @@ var exec = require('cordova/exec'),
* @param {Function} errorCB
* @param {CaptureVideoOptions} options
*/
-function _capture(type, successCallback, errorCallback, options) {
- var win = function(pluginResult) {
+function _capture (type, successCallback, errorCallback, options) {
+ var win = function (pluginResult) {
successCallback(helpers.wrapMediaFiles(pluginResult));
};
- exec(win, errorCallback, "Capture", type, [options]);
+ exec(win, errorCallback, 'Capture', type, [options]);
}
-
/**
* The Capture interface exposes an interface to the camera and microphone of the hosting device.
*/
-function Capture() {
+function Capture () {
this.supportedAudioModes = [];
this.supportedImageModes = [];
this.supportedVideoModes = [];
@@ -54,8 +53,8 @@ function Capture() {
* @param {Function} errorCB
* @param {CaptureAudioOptions} options
*/
-Capture.prototype.captureAudio = function(successCallback, errorCallback, options){
- _capture("captureAudio", successCallback, errorCallback, options);
+Capture.prototype.captureAudio = function (successCallback, errorCallback, options) {
+ _capture('captureAudio', successCallback, errorCallback, options);
};
/**
@@ -65,8 +64,8 @@ Capture.prototype.captureAudio = function(successCallback, errorCallback, option
* @param {Function} errorCB
* @param {CaptureImageOptions} options
*/
-Capture.prototype.captureImage = function(successCallback, errorCallback, options){
- _capture("captureImage", successCallback, errorCallback, options);
+Capture.prototype.captureImage = function (successCallback, errorCallback, options) {
+ _capture('captureImage', successCallback, errorCallback, options);
};
/**
@@ -76,9 +75,8 @@ Capture.prototype.captureImage = function(successCallback, errorCallback, option
* @param {Function} errorCB
* @param {CaptureVideoOptions} options
*/
-Capture.prototype.captureVideo = function(successCallback, errorCallback, options){
- _capture("captureVideo", successCallback, errorCallback, options);
+Capture.prototype.captureVideo = function (successCallback, errorCallback, options) {
+ _capture('captureVideo', successCallback, errorCallback, options);
};
-
module.exports = new Capture();
diff --git a/www/helpers.js b/www/helpers.js
index df726d99..b1a99fc6 100644
--- a/www/helpers.js
+++ b/www/helpers.js
@@ -1,44 +1,44 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-var MediaFile = require('./MediaFile');
-
-function wrapMediaFiles(pluginResult) {
- var mediaFiles = [];
- var i;
- for (i = 0; i < pluginResult.length; i++) {
- var mediaFile = new MediaFile();
- mediaFile.name = pluginResult[i].name;
-
- // Backwards compatibility
- mediaFile.localURL = pluginResult[i].localURL || pluginResult[i].fullPath;
- mediaFile.fullPath = pluginResult[i].fullPath;
- mediaFile.type = pluginResult[i].type;
- mediaFile.lastModifiedDate = pluginResult[i].lastModifiedDate;
- mediaFile.size = pluginResult[i].size;
- mediaFiles.push(mediaFile);
- }
- return mediaFiles;
-}
-
-module.exports = {
- wrapMediaFiles: wrapMediaFiles
-};
\ No newline at end of file
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+var MediaFile = require('./MediaFile');
+
+function wrapMediaFiles (pluginResult) {
+ var mediaFiles = [];
+ var i;
+ for (i = 0; i < pluginResult.length; i++) {
+ var mediaFile = new MediaFile();
+ mediaFile.name = pluginResult[i].name;
+
+ // Backwards compatibility
+ mediaFile.localURL = pluginResult[i].localURL || pluginResult[i].fullPath;
+ mediaFile.fullPath = pluginResult[i].fullPath;
+ mediaFile.type = pluginResult[i].type;
+ mediaFile.lastModifiedDate = pluginResult[i].lastModifiedDate;
+ mediaFile.size = pluginResult[i].size;
+ mediaFiles.push(mediaFile);
+ }
+ return mediaFiles;
+}
+
+module.exports = {
+ wrapMediaFiles: wrapMediaFiles
+};