cordova-plugin-video-trim
Advanced tools
Comparing version 1.0.0 to 2.0.0
{ | ||
"name": "cordova-plugin-video-trim", | ||
"version": "1.0.0", | ||
"description": "视频剪辑Cordova插件", | ||
"version": "2.0.0", | ||
"description": "视频剪辑功能的Cordova插件", | ||
"cordova": { | ||
"id": "cordova-plugin-video-trim", | ||
"platforms": [ | ||
"android" | ||
] | ||
"id": "cordova-plugin-video-trim" | ||
}, | ||
@@ -16,2 +13,3 @@ "repository": { | ||
"keywords": [ | ||
"cordova-plugin-video-trim", | ||
"cordova", | ||
@@ -18,0 +16,0 @@ "cordova-android", |
128
README.md
# cordova-plugin-video-trim | ||
截取短视频cordova插件,目前支持大于`cordova-android@8.0.0`版本 | ||
## 安装 | ||
短视频剪辑cordova插件 | ||
先安装依赖项插件 | ||
| 开发环境 | 版本 | | ||
| --------------- | ------- | | ||
| cordova | ≥ 9.0.0 | | ||
| cordova-android | ≥8.0.0 | | ||
```shell | ||
cordova plugin add cordova-plugin-device | ||
cordova plugin add cordova-plugin-media | ||
cordova plugin add cordova-plugin-media-capture | ||
``` | ||
`由于安卓版本碎片化问题,以上依赖项必须手动安装` | ||
> 视频剪辑需要在手机设备运行,安卓虚拟机无法剪辑 | ||
正式安装 cordova-plugin-video-trim | ||
## 安装 | ||
```shell | ||
cordova plugin add https://github.com/waitaction/cordova-plugin-video-trim.git | ||
``` shell | ||
cordova plugin add cordova-plugin-video-trim | ||
``` | ||
## 怎么用 | ||
## 方法列表 | ||
| 方法 | 描述 | | ||
| ---------------------------- | -------------------- | | ||
| videoTrim.trimVideo | 视频剪辑 | | ||
| videoTrim.trimSelectedVideo | 从相册选择视频后剪辑 | | ||
| videoTrim.trimRecordedVideo | 录像后前辑 | | ||
| videoTrim.play | 播放视频(允许全屏) | | ||
| videoTrim.getVideoPreviewImg | 获取视频预览图 | | ||
### 初始 cordova-plugin-video-trim | ||
```javascript | ||
videoTrimmer.init(function () { | ||
// 初始化成功 | ||
// todo | ||
}); | ||
### 视频剪辑 | ||
``` javascript | ||
videoTrim.trimVideo(videoPath,trimSuccess,trimFail); | ||
function trimSuccess(result) { | ||
console.log('trimSuccess, path: ' + result); | ||
} | ||
function trimFail(err) { | ||
console.log('trimFail, err: ' + err); | ||
} | ||
``` | ||
### 从视频选择对话框开始,选择源视频后截取视频片段 | ||
```javascript | ||
var dataDirectory = window.cordova.file.dataDirectory; | ||
var outPath = dataDirectory + "test.mp4"; // 输出最终短视频的路径 | ||
videoTrimmer.openSelectVideoPage({ outPath: outPath }, function (videoUrl) { | ||
// 截取视频片段成功,视频片段地址 videoUrl | ||
// 播放截取后的视频片段 | ||
videoTrimmer.play({ path:videoUrl },function(){ },function(){ }); // 播放 | ||
}, function (err) { | ||
// 截取视频片段失败 | ||
}); | ||
### 从相册选择视频后剪辑 | ||
``` javascript | ||
videoTrim.trimSelectedVideo(trimSuccess,trimFail); | ||
function trimSuccess(filePath) { | ||
console.log('trimSuccess, path: ' + filePath); | ||
} | ||
function trimFail(err) { | ||
console.log('trimFail, err: ' + err); | ||
} | ||
``` | ||
### 打开摄像头录制短视频 | ||
```javascript | ||
videoTrimmer.openRecordVideoPage({outPath:outPath},function (videoUrl) { | ||
// 截取视频片段成功,视频片段地址 videoUrl | ||
// todo | ||
}, function (error) { | ||
// 截取视频片段失败 | ||
}); | ||
### 录像后前辑 | ||
``` javascript | ||
videoTrim.trimRecordedVideo(trimSuccess,trimFail); | ||
function trimSuccess(filePath) { | ||
console.log('trimSuccess, path: ' + filePath); | ||
} | ||
function trimFail(err) { | ||
console.log('trimFail, err: ' + err); | ||
} | ||
``` | ||
### 输入源视频路径截取视频片段 | ||
### 获取视频预览图 | ||
```javascript | ||
videoTrimmer.openTrimmerPage({ path:sourcePath , outPath:targetPath },function(videoUrl){ | ||
// 截取视频片段成功,视频片段地址 videoUrl | ||
// todo | ||
},function(error){ | ||
// 截取视频片段失败 | ||
}); | ||
``` javascript | ||
videoTrim.getVideoPreviewImg(videoPath, | ||
function(url){ | ||
$("body").append("<img src='" + url + "' />"); | ||
}, | ||
function(){ | ||
console.log('error'); | ||
} | ||
); | ||
``` | ||
### 从视频截图封面图 | ||
### 播放视频(允许全屏) | ||
```javascript | ||
videoTrimmer.trimVideoImage({ path:data , outPath:imgPath },function(url){ | ||
$("body").append("<img src='" + url + "' />"); | ||
}); | ||
``` javascript | ||
videoTrim.play(videoPath,success,error); | ||
function success(){ | ||
} | ||
function error(){ | ||
} | ||
``` | ||
#### Demo | ||
## Demo | ||
### 可以下载 [示例项目](https://github.com/waitaction/cordova-plugin-video-trim-demo) | ||
<img src="https://github.com/iknow4/iknow.Images/blob/master/gif/videoTrim2.gif?raw=true" width="400" height="700" alt="videoTrim2"/> | ||
`cordova-plugin-video-trim插件部分代码来源 https://github.com/iknow4/Android-Video-Trimmer ` | ||
感谢开源项目 [Android-Video-Trimmer](https://github.com/iknow4/Android-Video-Trimmer) 提供部分安卓源代码 | ||
## 推荐其它开源库 | ||
[websql-orm](https://github.com/waitaction/websql-orm) | ||
@@ -5,14 +5,46 @@ | ||
/**打开视频截取页 */ | ||
Trimmer.prototype.openTrimmerPage = function (opt, success, error) { | ||
exec(success, error, "CordovaTrimmer", "openTrimmerPage", [opt]); | ||
/** | ||
* 视频剪辑 | ||
* 输入视频路径,成功输出剪辑后的视频路径 | ||
*/ | ||
Trimmer.prototype.trimVideo = function (videoPath, success, error) { | ||
var that = this; | ||
this.init(function () { | ||
var outPath = window.cordova.file.dataDirectory + (new Date()).getTime() + ".mp4"; // 输出路径 | ||
that.openTrimmerPage({ path: videoPath, outPath: outPath }, success, error); | ||
}, function (error) { | ||
error(error) | ||
}); | ||
} | ||
/**打开本地视频列表页 */ | ||
Trimmer.prototype.openSelectVideoPage = function (opt, success, error) { | ||
exec(success, error, "CordovaTrimmer", "openSelectVideoPage", [opt]); | ||
/** | ||
* 从相册选择视频后剪辑 | ||
*/ | ||
Trimmer.prototype.trimSelectedVideo = function (success, error) { | ||
var that = this; | ||
this.init(function () { | ||
var outPath = window.cordova.file.dataDirectory + (new Date()).getTime() + ".mp4"; // 输出路径 | ||
that.openSelectVideoPage({ outPath: outPath }, success, error); | ||
}, function (error) { | ||
error(error) | ||
}); | ||
} | ||
/**播放 */ | ||
Trimmer.prototype.play = function (opt, success, error) { | ||
/** | ||
* 录像后前辑 | ||
*/ | ||
Trimmer.prototype.trimRecordedVideo = function (success, error) { | ||
var that = this; | ||
this.init(function () { | ||
var outPath = window.cordova.file.dataDirectory + (new Date()).getTime() + ".mp4"; // 输出路径 | ||
that.openRecordVideoPage({ outPath: outPath }, success, error); | ||
}, function (error) { | ||
error(error) | ||
}); | ||
} | ||
/** | ||
* 播放视频(允许全屏) | ||
* */ | ||
Trimmer.prototype.play = function (videoPath, success, error) { | ||
// Play a video with callbacks | ||
@@ -32,5 +64,28 @@ var options = { | ||
}; | ||
window.plugins.streamingMedia.playVideo(opt.path, options); | ||
window.plugins.streamingMedia.playVideo(videoPath, options); | ||
} | ||
/** | ||
* 获取视频预览图 | ||
*/ | ||
Trimmer.prototype.getVideoPreviewImg = function (videoPath, success, error) { | ||
this.init(function () { | ||
var outPath = window.cordova.file.dataDirectory + (new Date()).getTime() + ".jpg"; // 输出路径 | ||
exec(success, error, "CordovaTrimmer", "trimVideoImage", [{ path: videoPath, outPath: outPath }]); | ||
}, function (error) { | ||
error(error) | ||
}); | ||
} | ||
/**打开视频截取页 */ | ||
Trimmer.prototype.openTrimmerPage = function (opt, success, error) { | ||
exec(success, error, "CordovaTrimmer", "openTrimmerPage", [opt]); | ||
} | ||
/**打开本地视频列表页 */ | ||
Trimmer.prototype.openSelectVideoPage = function (opt, success, error) { | ||
exec(success, error, "CordovaTrimmer", "openSelectVideoPage", [opt]); | ||
} | ||
/**打开摄像头录制视频 */ | ||
@@ -50,6 +105,34 @@ Trimmer.prototype.openRecordVideoPage = function (opt, success, error) { | ||
Trimmer.prototype.init = function (success, error) { | ||
exec(success, error, "CordovaTrimmer", "init", []); | ||
var permissions = cordova.plugins.permissions; | ||
permissions.hasPermission(permissions.CAMERA, function (status) { | ||
if (!status.hasPermission) { | ||
permissions.requestPermissions( | ||
[permissions.READ_EXTERNAL_STORAGE, permissions.WRITE_EXTERNAL_STORAGE], | ||
function () { | ||
exec(success, error, "CordovaTrimmer", "init", []); | ||
}, function () { | ||
console.warn('Camera permission is not turned on'); | ||
exec(success, error, "CordovaTrimmer", "init", []); | ||
}); | ||
} else { | ||
exec(success, error, "CordovaTrimmer", "init", []); | ||
} | ||
}); | ||
} | ||
Trimmer.prototype.iosTrim = function (success, error, options) { | ||
var self = this; | ||
var win = function (result) { | ||
if (typeof result.progress !== 'undefined') { | ||
if (typeof options.progress === 'function') { | ||
options.progress(result.progress); | ||
} | ||
} else { | ||
success(result); | ||
} | ||
}; | ||
exec(win, error, 'VideoTrim', 'trim', [options]); | ||
}; | ||
module.exports = new Trimmer(); | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
19736941
71
1927
100