要想实现更多功能 适应更多应用场景 肯定是要选择离线打包的

1.基础版: 只有录制和裁剪功能,
- 标准版:可以修改UI
- 专业版: 很复杂的功能
可以参考,阿里云SDK说明
如何没有离线打包过的,可以参考,官方最新的AS 打包教程:
ios离线打包教程
第一步
先下载ios短视频基础版SDK,详见sdk下载页面
1.开发者打开工程,选中目标target,依次选择”General”->”Embededed Binaries”,点击”+”号,点击“Add Other…”,导入QUCore-ThirdParty.framework和AliyunVideoSDK.framework。
2.同时,还需依赖libz.tbd、libc++.tbd、libiconv.tbd、libresolv.tbd、ImageIO.framework、CoreMedia.framework、CoreVideo.framework、SystemConfiguration.framework、Photos.framework、OpenAL.framework、VideoToolbox.framework请一并加上。截图如下
3.配置 Build Setting -- Build Options -- Enable Bitcode 选项为NO
4.配置 Build Setting -- Linking -- Other Linker Flags 添加 -ObjC选项
第二步
1.在HBuilder-Hello下新建文件夹recoredVideo 并在该文件夹下新建RecordVideo.h和RecordVideo.m文件
2.RecordVideo.h代码
include "PGPlugin.h"
include "PGMethod.h"
import <AliyunVideoSDK/AliyunVideoBase.h>
@interface RecordVideo : PGPlugin
- (void)record:(PGMethod*)commands;
- (void)videoBase:(AliyunVideoBase )base recordCompeleteWithRecordViewController:(UIViewController )recordVC videoPath:(NSString )videoPath;
-(NSString )getNowTimeTimestamp;
@end
3.RecordVideo.m代码
import "RecordVideo.h"
import <AliyunVideoSDK/AliyunVideoSDK.h>
import <AliyunVideoSDK/AliyunVideoRecordParam.h>
import <AliyunVideoSDK/AliyunVideoUIConfig.h>
import <AliyunVideoSDK/AliyunVideoBase.h>
import <AliyunVideoSDK/AliyunVideoCropParam.h>
import <AssetsLibrary/AssetsLibrary.h>
@interface RecordVideo()
@property (nonatomic,strong) NSString *callFunc;
@end
@implementation RecordVideo
-
(void)record:(PGMethod)commands
{
AliyunVideoUIConfig config = [[AliyunVideoUIConfig alloc] init];
config.hiddenFlashButton = NO;
config.imageBundleName = @"QPSDK";
config.hiddenImportButton = YES;
[[AliyunVideoBase shared] registerWithAliyunIConfig:config];NSString parameter0 = [commands.arguments objectAtIndex:0];
self.callFunc = [commands.arguments objectAtIndex:1];
NSData data= [parameter0 dataUsingEncoding:NSUTF8StringEncoding];
NSError error = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSDictionary dict = (NSDictionary )jsonObject;
AliyunVideoRecordParam quVideo = [[AliyunVideoRecordParam alloc] init];
quVideo.maxDuration = [[dict objectForKey:@"setMaxDuration"] doubleValue];
quVideo.minDuration = [[dict objectForKey:@"setMinDuration"] doubleValue];
quVideo.videoQuality = AliyunVideoQualityHight;
quVideo.torchMode = AliyunCameraTorchModeOff;
quVideo.size = AliyunVideoVideoSize540P;
quVideo.gop = [[dict objectForKey:@"setGop"] intValue];
quVideo.beautifyStatus = [[dict objectForKey:@"setBeautyStatus"] boolValue];
quVideo.beautifyValue = [[dict objectForKey:@"setBeautyLevel"] intValue];
quVideo.position = AliyunCameraPositionBack;
NSString path = [NSTemporaryDirectory() stringByAppendingPathComponent:[[self getNowTimeTimestamp] stringByAppendingString: @".mp4"]];
quVideo.outputPath = path;
UIViewController recordViewController = [[AliyunVideoBase shared] createRecordViewControllerWithRecordParam:quVideo];
[AliyunVideoBase shared].delegate = (id)self;
[self.rootViewController.navigationController pushViewController:recordViewController animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
} -
(void)videoBase:(AliyunVideoBase )base recordCompeleteWithRecordViewController:(UIViewController )recordVC videoPath:(NSString )videoPath {
NSLog(@"录制完成 %@", videoPath);
ALAssetsLibrary library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:videoPath]
completionBlock:^(NSURL assetURL, NSError error) {
NSString path = [@"file://" stringByAppendingPathComponent:videoPath];
NSDictionary dict = [NSDictionary dictionaryWithObjectsAndKeys:@"000000",@"code",path,@"path",nil];
PDRPluginResult *result = [PDRPluginResult resultWithStatus:PDRCommandStatusOK messageAsDictionary:dict];
[self toCallback:self.callFunc withReslut:[result toJSONString]];
dispatch_async(dispatch_get_main_queue(), ^{
[recordVC.navigationController popViewControllerAnimated:YES];
});
}];
}
-(void)videoBaseRecordVideoExit {
NSLog(@"退出录制");
[self.rootViewController.navigationController popViewControllerAnimated:YES];
}
-(NSString *)getNowTimeTimestamp{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ------ ----设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
//设置时区,这个对于时间的处理有时很重要
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[formatter setTimeZone:timeZone];
NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
return timeSp;
}
@end
第三步
1.打开PandoraApi.bundle下的feature.plist文件
2.feature.plist文件里加入
<key>RecordVideo</key>
<dict>
<key>class</key>
<string>RecordVideo</string>
<key>global</key>
<true/>
<key>autostart</key>
<string>YES</string>
</dict>
然后在html 页面 用JS通过 Native.js,调用原生类
var RecordVideoIos = function (options) {
this.options = this.extend(
{
setResolutionMode: '540p', // 录制 设置录制分辨率,目前支持360p,480p,540p,720p
setRatioMode: '1/1', // 录制 设置视频比例,目前支持1/1 ,3/4, 9/16
setRecordMode: 'AUTO', // 录制 设置录制模式,目前支持按录:PRESS,点录:TOUCH和混合模式:AUTO
setBeautyLevel: 80, // 录制 设置美颜度,1-100,比率
setBeautyStatus: true, // 录制 设置美颜开关
setCameraType: 'BACK', // 录制 设置前后置摄像头, 后:BACK ,前:FRONT
setFlashType: 'NO', // 录制 设置闪光灯模式,开:NO, 关:OFF, 自动:AUTO
setNeedClip: true, // 录制 设置是否需要支持片段录制
setMaxDuration: 15, // 录制 设置最大录制时长 单位秒
setMinDuration: 2, // 录制 设置最小录制时长 单位秒
setVideoQuality: 'HD', // 录制设置视频质量 4个级别, 低:LD ,中:SD ,高:HD ,极高:SSD
setGop: 125, // 设置关键帧间隔,建议:1-300之间
setMinVideoDuration: 5, // 裁剪 设置过滤的视频最小长度 单位秒
setMaxVideoDuration: 15, // 裁剪 设置过滤的视频最大长度 单位秒
setMinCropDuration: 2, // 裁剪 设置视频最小裁剪时间 单位毫秒
setFrameRate: 25, // 裁剪 设置帧率
setNeedRecord: false, // 设置是否需要开放录制入口,即选择视频的页面,多出一个录制按钮
setResulutionMode: '540p', // 设置裁剪分辨率,目前支持360p,480p,540p,720p
setCropMode: 'cpu' // 设置裁剪方式,是否使用gpu进行裁剪,不设置则默认使用cpu来裁剪
}, options)
this.init()
}
RecordVideoIos.prototype = {
init: function () {
this.event()
},
event: function () {
},
extend: function (obj, obj2) {
for (var k in obj2) {
obj[k] = obj2[k]
}
return obj
},
open: function (fn) {
let B = window.plus.bridge
let success = typeof fn !== 'function' ? null : function (args) {
fn(args)
}
let callbackID = B.callbackId(success, null)
return B.exec('RecordVideo', 'record', [JSON.stringify(this.options), callbackID])
}
}
const option = {
setResolutionMode: '720p', // 录制 设置录制分辨率,目前支持360p,480p,540p,720p
setRatioMode: '1/1', // 录制 设置视频比例,目前支持1/1 ,3/4, 9/16
setRecordMode: 'AUTO', // 录制 设置录制模式,目前支持按录:PRESS,点录:TOUCH和混合模式:AUTO
setBeautyLevel: 60, // 录制 设置美颜度,1-100,比率
setBeautyStatus: true, // 录制 设置美颜开关
setCameraType: 'BACK', // 录制 设置前后置摄像头, 后:BACK ,前:FRONT
setFlashType: 'OFF', // 录制 设置闪光灯模式,开:NO, 关:OFF, 自动:AUTO
setNeedClip: true, // 录制 设置是否需要支持片段录制
setMaxDuration: 15, // 录制 设置最大录制时长 单位秒
setMinDuration: 2, // 录制 设置最小录制时长 单位秒
setVideoQuality: 'HD', // 录制设置视频质量 4个级别, 低:LD ,中:SD ,高:HD ,极高:SSD
setGop: 125, // 设置关键帧间隔,建议:1-300之间
setMinVideoDuration: 5, // 裁剪 设置过滤的视频最小长度 单位秒
setMaxVideoDuration: 15, // 裁剪 设置过滤的视频最大长度 单位秒
setMinCropDuration: 2, // 裁剪 设置视频最小裁剪时间 单位毫秒
setFrameRate: 25, // 裁剪 设置帧率
setNeedRecord: false, // 设置是否需要开放录制入口,即选择视频的页面,多出一个录制按钮
setResulutionMode: '540p', // 设置裁剪分辨率,目前支持360p,480p,540p,720p
setCropMode: 'cpu' // 设置裁剪方式,是否使用gpu进行裁剪,不设置则默认使用cpu来裁剪
}
var recordVideoIos = new RecordVideoIos(option)
if (plus.os.name != 'Android') {
window.plus.recordVideo = recordVideoIos
}
就这么多了,不懂的可以加群864017187(dcloud混合开发交流群)