# captureVideo
录制视频,来源自 Cordova API (opens new window)。
# 输入
继承标准对象输入,扩展属性描述
| 名称 | 数据类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| params | Object | 是 | 详情见下面params参数说明 |
params参数说明:
| 名称 | 数据类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| limit | int | 是 | 1 | 录制视频次数 |
| duration | int | 否 | 可以限制时长自动结束(新版本Cordova才支持,低版本不支持) | |
| cameraDirection | int | 是 | 0表示后置;1表示前置 | |
| quality | int | 否 | 0表示低质量;1表示高质量;不填表示中质量(新版本Cordova才支持,低版本不支持) |
# 输出
继承标准对象输出,无扩展属性
# 示例代码一
// 定义capture拍照方法的成功回调函数和失败回调函数
//用这个方法ios需要引进对应的插件cordova-plugin-media-capture和cordova-plugin-video-editor
//压缩视频需要区分端,使用不同的方法
var success = function(mediaFiles) {
var i, path, len, fileName;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles[i].fullPath;
fileName = mediaFiles[i].name;
bui.alert(path);
}
var outputFile = path.substr(0, path.lastIndexOf('/')) + '/198.mp4';
if(window.devicePlatform=="android"){
app.link.compressedVideo((res) => {
bui.alert(res);
}, (error) => {
bui.alert('error' + error);
}, {
inputFile: path,
outputFile: outputFile
})
}else if(window.devicePlatform=="iOS"){
app.link.transcodeVideo((res) => {
bui.alert(res);
}, (error) => {
bui.alert('error' + error);
}, {
fileUri: path,
outputFileName: fileName,
outputFileType: 1,
saveToLibrary: true,
maintainAspectRatio: true,
width: 640, //可选
height: 640, //可选
audioChannels: 1,
progress: function (info) {
// 压缩进度
}
})
}
};
// capture error callback
var fail = function(error) {
navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
};
//录像,limit:1 可以改变录像几次, duration: 20可以可以限制时长自动结束, cameraDirection(0表示后置;1表示前置),quality(0表示低质量;1表示高质量;不填表示中质量)
navigator.device.capture.captureVideo(success, fail, {limit:1, duration: 5, cameraDirection: 1, quality: 1});
# 示例代码二
//录屏方法,具有倒计时能力
app.link.captureVideo(res => {
bui.alert(res);
}, err => {
bui.alert(err);
}, example_duration);