DedrisFrameworkDedrisFramework

← Plugins  /  Media Capture

🎥

Media Capture

cordova-plugin-media-capture
iOS Android

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.

Installation

terminal
cordova plugin add cordova-plugin-media-capture

API

The plugin lives on navigator.device.capture. Call these after deviceready:

MethodDescription
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.

Options & result

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:

PropertyDescription
nameThe file name without the path.
fullPathThe full path to the file on the device.
typeThe MIME type, e.g. image/jpeg.
sizeThe file size in bytes.

Usage example

Let the user record up to two short videos:

www/js/app.js
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 }
  );
}

Tips

📚 Source: the technical reference on this page (the methods, options and the MediaFile object) is based on the official Apache Cordova media-capture documentation. Descriptions and examples have been rewritten in DedrisFramework's own words. Apache Cordova documentation is published by the Apache Software Foundation under the Apache License 2.0.
← Back to plugins Start a project