The 2017 Ionic Developer Survey Results are in!

Media Capture

Improve this doc

Repo: https://github.com/apache/cordova-plugin-media-capture

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-media-capture
    $ npm install --save @ionic-native/media-capture
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { MediaCapture, MediaFile, CaptureError, CaptureImageOptions } from '@ionic-native/media-capture';


constructor(private mediaCapture: MediaCapture) { }

...


let options: CaptureImageOptions = { limit: 3 };
this.mediaCapture.captureImage(options)
  .then(
    (data: MediaFile[]) => console.log(data),
    (err: CaptureError) => console.error(err)
  );

Instance Members

supportedImageModes

The recording image sizes and formats supported by the device.

Returns: ConfigurationData[]

supportedAudioModes

The audio recording formats supported by the device.

Returns: ConfigurationData[]

supportedVideoModes

The recording video resolutions and formats supported by the device.

Returns: ConfigurationData[]

captureAudio(options)

Start the audio recorder application and return information about captured audio clip files.

Param Type Details
options

Returns: Promise<MediaFile[]>

captureImage(options)

Start the camera application and return information about captured image files.

Param Type Details
options

Returns: Promise<MediaFile[]>

captureVideo(options)

Start the video recorder application and return information about captured video clip files.

Param Type Details
options

Returns: Promise<MediaFile[]>

onPendingCaptureResult()

is fired if the capture call is successful

Returns: Observable<MediaFile[]>

onPendingCaptureError()

is fired if the capture call is unsuccessful

Returns: Observable<CaptureError>

MediaFile

Param Type Details
name string

The name of the file, without path information.

fullPath string

The full path of the file, including the name.

type string

The file's mime type

lastModifiedDate Date

The date and time when the file was last modified.

size number

The size of the file, in bytes.

getFormatData void

Retrieves the format information of the media file.

MediaFileData

Param Type Details
codecs string

The actual format of the audio and video content.

bitrate number

The average bitrate of the content. The value is zero for images.

height number

The height of the image or video in pixels. The value is zero for audio clips.

width number

The width of the image or video in pixels. The value is zero for audio clips.

duration number

The length of the video or sound clip in seconds. The value is zero for images.

CaptureError

Param Type Details
code string

CaptureAudioOptions

Param Type Details
limit number

Maximum number of audio clips. Defaults to 1. On iOS you can only record one file.

(optional)
duration number

Maximum duration of an audio sound clip, in seconds. This does not work on Android devices.

(optional)

CaptureImageOptions

Param Type Details
limit number

Maximum number of images to capture. This limit is not supported on iOS, only one image will be taken per invocation.

(optional)

CaptureVideoOptions

Param Type Details
limit number

Maximum number of video clips to record. This value is ignored on iOS, only one video clip can be taken per invocation.

(optional)
duration number

Maximum duration per video clip. This will be ignored on BlackBerry.

(optional)
quality number

Quality of the video. This parameter can only be used with Android.

(optional)

ConfigurationData

Param Type Details
type string

The ASCII-encoded lowercase string representing the media type.

height number

The height of the image or video in pixels. The value is zero for sound clips.

width number

The width of the image or video in pixels. The value is zero for sound clips.

API

Native

General