capture.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. var exec = require('cordova/exec'),
  22. MediaFile = require('./MediaFile');
  23. /**
  24. * Launches a capture of different types.
  25. *
  26. * @param (DOMString} type
  27. * @param {Function} successCB
  28. * @param {Function} errorCB
  29. * @param {CaptureVideoOptions} options
  30. */
  31. function _capture(type, successCallback, errorCallback, options) {
  32. var win = function(pluginResult) {
  33. var mediaFiles = [];
  34. var i;
  35. for (i = 0; i < pluginResult.length; i++) {
  36. var mediaFile = new MediaFile();
  37. mediaFile.name = pluginResult[i].name;
  38. // Backwards compatibility
  39. mediaFile.localURL = pluginResult[i].localURL || pluginResult[i].fullPath;
  40. mediaFile.fullPath = pluginResult[i].fullPath;
  41. mediaFile.type = pluginResult[i].type;
  42. mediaFile.lastModifiedDate = pluginResult[i].lastModifiedDate;
  43. mediaFile.size = pluginResult[i].size;
  44. mediaFiles.push(mediaFile);
  45. }
  46. successCallback(mediaFiles);
  47. };
  48. exec(win, errorCallback, "Capture", type, [options]);
  49. }
  50. /**
  51. * The Capture interface exposes an interface to the camera and microphone of the hosting device.
  52. */
  53. function Capture() {
  54. this.supportedAudioModes = [];
  55. this.supportedImageModes = [];
  56. this.supportedVideoModes = [];
  57. }
  58. /**
  59. * Launch audio recorder application for recording audio clip(s).
  60. *
  61. * @param {Function} successCB
  62. * @param {Function} errorCB
  63. * @param {CaptureAudioOptions} options
  64. */
  65. Capture.prototype.captureAudio = function(successCallback, errorCallback, options){
  66. _capture("captureAudio", successCallback, errorCallback, options);
  67. };
  68. /**
  69. * Launch camera application for taking image(s).
  70. *
  71. * @param {Function} successCB
  72. * @param {Function} errorCB
  73. * @param {CaptureImageOptions} options
  74. */
  75. Capture.prototype.captureImage = function(successCallback, errorCallback, options){
  76. _capture("captureImage", successCallback, errorCallback, options);
  77. };
  78. /**
  79. * Launch device camera application for recording video(s).
  80. *
  81. * @param {Function} successCB
  82. * @param {Function} errorCB
  83. * @param {CaptureVideoOptions} options
  84. */
  85. Capture.prototype.captureVideo = function(successCallback, errorCallback, options){
  86. _capture("captureVideo", successCallback, errorCallback, options);
  87. };
  88. module.exports = new Capture();