Appearance
媒体捕获
只列出部分主要功能,其他功能及参数详细说明请参考官方文档https://www.npmjs.com/package/cordova-plugin-media-capture
介绍
cordova-plugin-media-capture 对设备的音频、图像和视频捕获
主要功能
录音
示例
js
var captureSuccess = function (mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles[i].fullPath;
// do something interesting with the file
}
};
var captureError = function (error) {
navigator.notification.alert(
"Error code: " + error.code,
null,
"Capture Error"
);
};
// start audio capture
navigator.device.capture.captureAudio(captureSuccess, captureError, {
limit: 2,
});
拍照
示例
js
var captureSuccess = function (mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles[i].fullPath;
// do something interesting with the file
}
};
var captureError = function (error) {
navigator.notification.alert(
"Error code: " + error.code,
null,
"Capture Error"
);
};
// start image capture
navigator.device.capture.captureImage(captureSuccess, captureError, {
limit: 2,
});
录制视频
示例
js
var captureSuccess = function (mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles[i].fullPath;
// do something interesting with the file
}
};
var captureError = function (error) {
navigator.notification.alert(
"Error code: " + error.code,
null,
"Capture Error"
);
};
// iOS The limit property is ignored. Only one video is recorded per invocation.
var options = { limit: 1, quality: 0, duration: 10 };
// start image capture
navigator.device.capture.captureVideo(captureSuccess, captureError, options);