Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(media-capture): add media capture plugin #293

Merged
merged 1 commit into from
Jul 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {Insomnia} from './plugins/insomnia';
import {Keyboard} from './plugins/keyboard';
import {LaunchNavigator} from './plugins/launchnavigator';
import {LocalNotifications} from './plugins/localnotifications';
import {MediaCapture} from './plugins/media-capture';
import {MediaPlugin} from './plugins/media';
import {Network} from './plugins/network';
import {OneSignal} from './plugins/onesignal';
Expand Down Expand Up @@ -90,6 +91,7 @@ export * from './plugins/inappbrowser';
export * from './plugins/launchnavigator';
export * from './plugins/localnotifications';
export * from './plugins/media';
export * from './plugins/media-capture';
export * from './plugins/printer';
export * from './plugins/push';
export * from './plugins/safari-view-controller';
Expand Down Expand Up @@ -188,6 +190,7 @@ window['IonicNative'] = {
Keyboard: Keyboard,
LaunchNavigator: LaunchNavigator,
LocalNotifications: LocalNotifications,
MediaCapture: MediaCapture,
MediaPlugin: MediaPlugin,
Network: Network,
Printer: Printer,
Expand Down
218 changes: 218 additions & 0 deletions src/plugins/media-capture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
import {Plugin, Cordova, CordovaProperty} from './plugin';
import {Observable} from 'rxjs/Rx';
/**
* @name Media Capture
* @description
* @usage
* ```typescript
* import {MediaCapture} from 'ionic-native';
*
* ...
*
* let options: CaptureImageOptions = { limit: 3 };
* MediaCapture.captureImage(options)
* .then(
* (data: MediaFile[]) => console.log(data),
* (err: CaptureError) => console.error(err)
* );
*
* ```
*/
@Plugin({
plugin: 'cordova-plugin-media-capture',
pluginRef: 'navigator.device.capture',
repo: 'https://github.com/apache/cordova-plugin-media-capture'
})
export class MediaCapture {
/**
* The audio recording formats supported by the device.
* @returns {ConfigurationData[]}
*/
@CordovaProperty
static get supportedImageModes(): ConfigurationData[] {
return <ConfigurationData[]>navigator.device.capture.supportedImageModes;
}

/**
* The recording image sizes and formats supported by the device.
* @returns {ConfigurationData[]}
*/
@CordovaProperty
static get supportedAudioModes(): ConfigurationData[] {
return <ConfigurationData[]>navigator.device.capture.supportedAudioModes;
}

/**
* The recording video resolutions and formats supported by the device.
* @returns {ConfigurationData[]}
*/
@CordovaProperty
static get supportedVideoModes(): ConfigurationData[] {
return <ConfigurationData[]>navigator.device.capture.supportedVideoModes;
}

/**
* Start the audio recorder application and return information about captured audio clip files.
* @param options
*/
@Cordova({
callbackOrder: 'reverse'
})
static captureAudio(options?: CaptureAudioOptions): Promise<MediaFile[]|CaptureError> {return; }

/**
* Start the camera application and return information about captured image files.
* @param options
*/
@Cordova({
callbackOrder: 'reverse'
})
static captureImage(options?: CaptureImageOptions): Promise<MediaFile[]|CaptureError> {return; }

/**
* Start the video recorder application and return information about captured video clip files.
* @param options
*/
@Cordova({
callbackOrder: 'reverse'
})
static captureVideo(options?: CaptureVideoOptions): Promise<MediaFile[]|CaptureError> {return; }

/**
* is fired if the capture call is successful
*/
@Cordova({
eventObservable: true,
event: 'pendingcaptureresult'
})
static onPendingCaptureResult(): Observable<MediaFile[]> {return; }

/**
* is fired if the capture call is unsuccessful
*/
@Cordova({
eventObservable: true,
event: 'pendingcaptureerror'
})
static onPendingCaptureError(): Observable<CaptureError> {return; }

}
/**
* Encapsulates properties of a media capture file.
*/
export 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 the format information of the media file.
* @param {Function} successCallback
* @param {Function} errorCallback
*/
getFormatData(successCallback: (data: MediaFileData) => any, errorCallback?: (err: any) => any);
}
/**
* Encapsulates format information about a media file.
*/
export 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.
*/
export interface CaptureError {
code: string;
}
/**
* Encapsulates audio capture configuration options.
*/
export interface CaptureAudioOptions {
/**
* Maximum number of audio clips. Defaults to 1.
* On iOS you can only record one file.
*/
limit?: number;
/**
* Maximum duration of an audio sound clip, in seconds. This does not work on Android devices.
*/
duration?: number;
}
/**
* Encapsulates image capture configuration options.
*/
export interface CaptureImageOptions {
/**
* Maximum number of images to capture. This limit is not supported on iOS, only one image will be taken per invocation.
*/
limit?: number;
}
/**
* Encapsulates video capture configuration options.
*/
export interface CaptureVideoOptions {
/**
* Maximum number of video clips to record. This value is ignored on iOS, only one video clip can be taken per invocation.
*/
limit?: number;
/**
* Maximum duration per video clip. This will be ignored on BlackBerry.
*/
duration?: number;
/**
* Quality of the video. This parameter can only be used with Android.
*/
quality?: number;
}
/**
* Encapsulates a set of media capture parameters that a device supports.
*/
export 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;
}