index.d.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import { AwesomeCordovaNativePlugin } from '@awesome-cordova-plugins/core';
  2. import { Observable } from 'rxjs';
  3. export interface MediaFile {
  4. /**
  5. * The name of the file, without path information.
  6. */
  7. name: string;
  8. /**
  9. * The full path of the file, including the name.
  10. */
  11. fullPath: string;
  12. /**
  13. * The file's mime type
  14. */
  15. type: string;
  16. /**
  17. * The date and time when the file was last modified.
  18. */
  19. lastModifiedDate: Date;
  20. /**
  21. * The size of the file, in bytes.
  22. */
  23. size: number;
  24. /**
  25. * Retrieves the format information of the media file.
  26. *
  27. * @param {Function} successCallback
  28. * @param {Function} errorCallback
  29. */
  30. getFormatData(successCallback: (data: MediaFileData) => any, errorCallback?: (err: any) => any): void;
  31. }
  32. export interface MediaFileData {
  33. /**
  34. * The actual format of the audio and video content.
  35. */
  36. codecs: string;
  37. /**
  38. * The average bitrate of the content. The value is zero for images.
  39. */
  40. bitrate: number;
  41. /**
  42. * The height of the image or video in pixels. The value is zero for audio clips.
  43. */
  44. height: number;
  45. /**
  46. * The width of the image or video in pixels. The value is zero for audio clips.
  47. */
  48. width: number;
  49. /**
  50. * The length of the video or sound clip in seconds. The value is zero for images.
  51. */
  52. duration: number;
  53. }
  54. export interface CaptureError {
  55. code: string;
  56. }
  57. export interface CaptureAudioOptions {
  58. /**
  59. * Maximum number of audio clips. Defaults to 1.
  60. * On iOS you can only record one file.
  61. */
  62. limit?: number;
  63. /**
  64. * Maximum duration of an audio sound clip, in seconds. This does not work on Android devices.
  65. */
  66. duration?: number;
  67. }
  68. export interface CaptureImageOptions {
  69. /**
  70. * Maximum number of images to capture. This limit is not supported on iOS, only one image will be taken per invocation.
  71. */
  72. limit?: number;
  73. }
  74. export interface CaptureVideoOptions {
  75. /**
  76. * Maximum number of video clips to record. This value is ignored on iOS, only one video clip can be taken per invocation.
  77. */
  78. limit?: number;
  79. /**
  80. * Maximum duration per video clip. This will be ignored on BlackBerry.
  81. */
  82. duration?: number;
  83. /**
  84. * Quality of the video. This parameter can only be used with Android.
  85. */
  86. quality?: number;
  87. }
  88. export interface ConfigurationData {
  89. /**
  90. * The ASCII-encoded lowercase string representing the media type.
  91. */
  92. type: string;
  93. /**
  94. * The height of the image or video in pixels. The value is zero for sound clips.
  95. */
  96. height: number;
  97. /**
  98. * The width of the image or video in pixels. The value is zero for sound clips.
  99. */
  100. width: number;
  101. }
  102. /**
  103. * @name Media Capture
  104. * @premier media-capture
  105. * @description
  106. * This plugin provides access to the device's audio, image, and video capture capabilities.
  107. *
  108. * Requires Cordova plugin: `cordova-plugin-media-capture`. For more info, please see the [Media Capture plugin docs](https://github.com/apache/cordova-plugin-media-capture).
  109. * @usage
  110. * ```typescript
  111. * import { MediaCapture, MediaFile, CaptureError, CaptureImageOptions } from '@awesome-cordova-plugins/media-capture/ngx';
  112. *
  113. *
  114. * constructor(private mediaCapture: MediaCapture) { }
  115. *
  116. * ...
  117. *
  118. *
  119. * let options: CaptureImageOptions = { limit: 3 }
  120. * this.mediaCapture.captureImage(options)
  121. * .then(
  122. * (data: MediaFile[]) => console.log(data),
  123. * (err: CaptureError) => console.error(err)
  124. * );
  125. *
  126. * ```
  127. * @interfaces
  128. * MediaFile
  129. * MediaFileData
  130. * CaptureError
  131. * CaptureAudioOptions
  132. * CaptureImageOptions
  133. * CaptureVideoOptions
  134. * ConfigurationData
  135. */
  136. export declare class MediaCapture extends AwesomeCordovaNativePlugin {
  137. /**
  138. * The recording image sizes and formats supported by the device.
  139. *
  140. * @returns {ConfigurationData[]}
  141. */
  142. supportedImageModes: ConfigurationData[];
  143. /**
  144. * The audio recording formats supported by the device.
  145. *
  146. * @returns {ConfigurationData[]}
  147. */
  148. supportedAudioModes: ConfigurationData[];
  149. /**
  150. * The recording video resolutions and formats supported by the device.
  151. *
  152. * @returns {ConfigurationData[]}
  153. */
  154. supportedVideoModes: ConfigurationData[];
  155. /**
  156. * Start the audio recorder application and return information about captured audio clip files.
  157. *
  158. * @param options
  159. * @returns {Promise<MediaFile[]>}
  160. */
  161. captureAudio(options?: CaptureAudioOptions): Promise<MediaFile[] | CaptureError>;
  162. /**
  163. * Start the camera application and return information about captured image files.
  164. *
  165. * @param options
  166. * @returns {Promise<MediaFile[]>}
  167. */
  168. captureImage(options?: CaptureImageOptions): Promise<MediaFile[] | CaptureError>;
  169. /**
  170. * Start the video recorder application and return information about captured video clip files.
  171. *
  172. * @param options
  173. * @returns {Promise<MediaFile[]>}
  174. */
  175. captureVideo(options?: CaptureVideoOptions): Promise<MediaFile[] | CaptureError>;
  176. /**
  177. * is fired if the capture call is successful
  178. *
  179. * @returns {Observable<MediaFile[]>}
  180. */
  181. onPendingCaptureResult(): Observable<MediaFile[]>;
  182. /**
  183. * is fired if the capture call is unsuccessful
  184. *
  185. * @returns {Observable<CaptureError>}
  186. */
  187. onPendingCaptureError(): Observable<CaptureError>;
  188. }