SDK 支持 iOS 8.0 以上系统。
将下载的 SDK 资源包解压,并将 SDK 文件夹中 TXLiteAVSDK_ 开头的 framework(如 TXLiteAVSDK_UGC.framework)复制到工程所在文件夹,并拖动到工程当中。
bitcode
,将 Enable Bitcode 设置为 NO。应用会需要相册及相册的访问权限,需要在 Info.plist 中添加对应项,可以通过在 Info.plist 中右键选 Open as / Source Code 粘贴并修改以下内容进行配置。
<key>NSAppleMusicUsageDescription</key>
<string>视频云工具包需要访问您的媒体库权限以获取音乐,不允许则无法添加音乐</string>
<key>NSCameraUsageDescription</key>
<string>视频云工具包需要访问您的相机权限,开启后录制的视频才会有画面</string>
<key>NSMicrophoneUsageDescription</key>
<string>视频云工具包需要访问您的麦克风权限,开启后录制的视频才会有声音</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>视频云工具包需要访问您的相册权限,开启后才能保存编辑的文件</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>视频云工具包需要访问您的相册权限,开启后才能编辑视频文件</string>
通过 License 申请 的指引申请 License 后,从 控制台 复制 key 和 url,见下图。
2. 在您的应用中使用短视频功能之前,建议在- [AppDelegate application:didFinishLaunchingWithOptions:]
中进行如下设置:
@import TXLiteAVSDK_UGC;
@implementation AppDelegate
- (BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictinoary*)options {
NSString * const licenceURL = @"<获取到的licnseUrl>";
NSString * const licenceKey = @"<获取到的key>";
[TXUGCBase setLicenceURL:licenceURL key:licenceKey];
NSLog(@"SDK Version = %@", [TXLiveBase getSDKVersionStr]);
}
@end
说明:对于使用4.7版本 License 的用户,如果您升级了 SDK 到4.9版本,您可以登录控制台,单击下图的 切换到新版License 生成对应的 key 和 url,切换后的 License 必须使用4.9及更高的版本,切换后按照上述操作集成即可。
在 TXLiveBase 中可以设置 log 是否在控制台打印以及 log 的级别,相关接口如下:
[TXLiveBase setConsoleEnabled:YES];
[TXLiveBase setLogLevel:LOGLEVEL_DEBUG];
如果前面各步骤都操作正确的话,HelloSDK 工程就可以顺利编译通过。在 Debug 模式下运行 App,Xcode 的 Console 窗格会打印出 SDK 的版本信息:
2017-09-26 16:16:15.767 HelloSDK[17929:7488566] SDK Version = 5.2.5541
为了方便您快速集成 SDK 各项功能,我们提供了 UGCKit。UGCKit 是在短视频 SDK 基础上构建的一套 UI 组件库。
您可以通过 GitHub 或 资源下载 中提供的 SDK 压缩包获取 UGCKit。UGCKit 位于压缩包 Demo/TXLiteAVDemo/UGC/UGCKit 目录下。
pod init && pod install
,可得到 Podfile 文件。打开 Podfile 文件,增加:
pod 'UGCKit', :path => 'UGCKit/UGCKit.podspec', :subspecs => ["UGC"] #subspecs 根据SDK来选择
如果集成基础美颜,把BeautySettingKit文件夹拷贝到项目根目录下(Podfile 同级目录),并且在Podfile文件中,增加:
pod 'BeautySettingKit', :path => 'BeautySettingKit/BeautySettingKit.podspec'
如果集成腾讯特效,把xmagickit文件夹拷贝到项目根目录下(Podfile 同级目录),并且在Podfile文件中增加:
pod 'xmagickit', :path => 'xmagickit/xmagickit.podspec'
执行 pod install,并打开 项目名.xcworkspace
,可以看到在 Pods/Development Pods
目录下已有 UGCKit BeautySettingKit x magickit
。
UGCKitRecordViewController
提供了完整的录制功能,您只需实例化这个控制器后展现在界面中即可。UGCKitRecordViewController *recordViewController = [[UGCKitRecordViewController alloc] initWithConfig:nil theme:nil];
[self.navigationController pushViewController:recordViewController]
录制后的结果将通过 completion block 回调,示例如下:
recordViewController.completion = ^(UGCKitResult *result) {
if (result.error) {
// 录制出错
[self showAlertWithError:error];
} else {
if (result.cancelled) {
// 用户取消录制,退出录制界面
[self.navigationController popViewControllerAnimated:YES];
} else {
// 录制成功, 用结果进行下一步处理
[self processRecordedVideo:result.media];
}
}
};
UGCKitEditViewController
提供了完整的图片转场和视频编辑功能,实例化时需要传入待编辑的媒体对象,以处理录制结果为例,示例如下:- (void)processRecordedVideo:(UGCKitMedia *)media {
// 实例化编辑控制器
UGCKitEditViewController *editViewController = [[UKEditViewController alloc] initWithMedia:media conifg:nil theme:nil];
// 展示编辑控制器
[self.navigationController pushViewController:editViewController animated:YES];
编辑后的结果将通过 completion block 回调,示例如下:
editViewController.completion = ^(UGCKitResult *result) {
if (result.error) {
// 出错
[self showAlertWithError:error];
} else {
if (result.cancelled) {
// 用户取消录制,退出编辑界面
[self.navigationController popViewControllerAnimated:YES];
} else {
// 编辑保存成功, 用结果进行下一步处理
[self processEditedVideo:result.path];
}
}
}
从相册中选择视频或图片
UGCKitMediaPickerViewController
用来处理媒体的选择与合并,当选择多个视频时,将会返回拼接后的视频,示例如下:
// 初始化配置
UGCKitMediaPickerConfig *config = [[UGCKitMediaPickerConfig alloc] init];
config.mediaType = UGCKitMediaTypeVideo;//选择视频
config.maxItemCount = 5; //最多选5个
// 实例化媒体选择器
UGCKitMediaPickerViewController *mediaPickerViewController = [[UGCKitMediaPickerViewController alloc] initWithConfig:config theme:nil];
// 展示媒体选择器
[self presentViewController:mediaPickerViewController animated:YES completion:nil];
选择的结果将通过 completion block 回调,示例如下:
mediaPickerViewController.completion = ^(UGCKitResult *result) {
if (result.error) {
// 出错
[self showAlertWithError:error];
} else {
if (result.cancelled) {
// 用户取消录制,退出选择器界面
[self dismissViewControllerAnimated:YES completion:nil];
} else {
// 编辑保存成功, 用结果进行下一步处理
[self processEditedVideo:result.media];
}
}
}
裁剪UGCKitCutViewController
提供视频的裁剪功能,与编辑接口相同,在实例化时传入媒体对象,在 completion 中处理剪辑结果即可。示例如下:
UGCKitMedia *media = [UGCKitMedia mediaWithVideoPath:@"<#视频路径#>"];
UGCKitCutViewController *cutViewController = [[UGCKitCutViewController alloc] initWithMedia:media theme:nil];
cutViewController.completion = ^(UGCKitResult *result) {
if (!result.cancelled && !result.error) {
[self editVideo:result.media];
} else {
[self.navigationController popViewControllerAnimated:YES];
}
}
[self.navigationController pushViewController: cutViewController]
以下为 SDK 各模块的详细说明:
本页内容是否解决了您的问题?