← Plugins / Media Capture
This official Apache Cordova plugin captures photos, audio clips and video using the device's
built-in capture apps. Each call returns an array of MediaFile objects describing
the files that were recorded, which you can then upload, play or store.
cordova plugin add cordova-plugin-media-capture
The plugin lives on navigator.device.capture. Call these after deviceready:
| Method | Description |
|---|---|
captureImage(success, error, options) | Open the camera to take one or more photos. |
captureAudio(success, error, options) | Open the sound recorder to capture audio clips. |
captureVideo(success, error, options) | Open the camera to record one or more videos. |
The options object accepts limit (max files to capture) and, for audio/video, duration (max seconds). On success you receive an array of MediaFile objects:
| Property | Description |
|---|---|
name | The file name without the path. |
fullPath | The full path to the file on the device. |
type | The MIME type, e.g. image/jpeg. |
size | The file size in bytes. |
Let the user record up to two short videos:
function recordVideo() {
navigator.device.capture.captureVideo(
function (files) {
files.forEach(function (f) {
console.log(f.name + " — " + f.size + " bytes");
});
},
function (err) {
console.error("Capture error: " + err.code);
},
{ limit: 2, duration: 30 }
);
}
fullPath is a device path — pair it with the File plugin to read or upload the result.