轻松将Nimbb的视频录制功能集成到你的iOS项目中。 Nimbb 是一个云端的全方位服务,提供所有你需要的功能来录制、托管和回放用户生成视频。所有视频都存储在我们的服务器上,这样你只需要关注客户端侧。请参考我们的 定价 页面以获取完整的功能列表和价格。
要使用iOS的Nimbb库,首先创建你的Nimbb账户。需要银牌(或以上)计划才能在iOS中录制或回放视频。 联系我们 获取试用期限。
你还需要在你的Nimbb的开发者设置中添加一个“iOS应用”条目。指定Xcode项目的“Bundle ID”。
platform :ios, '7.0'
pod "NimbbLibrary", "~> 1.0"
你将NimbbLib.framework从Vendor目录复制到你的项目中。
NimbbLib.framework需要AFNetworking 2.x才能工作。因此,在使用NimbbLib.framework之前,你需要安装它。
你需要在“构建过程”->“链接二进制与库”中添加以下库
/usr/include/libxml2
-ObjC
在你开始录制视频之前,你需要使用你的Nimbb账户中的开发者秘钥来初始化播放器。
[NimbbPlayer initPlayerConfigurationUsingDeveloperPublicKey:@"YOURPUBLICKEY"
videoLength:30
videoQuality:NimbbPlayerQualityMedium
forceDev:NO
configurationCompletedHandler:^{
NSLog(@"You're ready to record videos!");
}
configurationFailedHandler:^(NSError *error) {
NSLog(@"oh no!");
}
];
当播放器成功初始化后,你可以开始通过仅一个方法来录制视频...就这么简单!
[NimbbPlayer startCaptureVideoFromViewController:self
videoUploadProgressionHandler:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
float percent = ((float)totalBytesWritten / (float)totalBytesExpectedToWrite);
NSLog(@"Uploading video... %f / 100",percent*100.0f);
}
videoSavedHandler:^(NSString *nimbbVideoGuid) {
NSLog(@"http://nimbb.com/v/%@", nimbbVideoGuid);
}
videoCanceledHandler:^{
NSLog(@"Video canceled...");
}
captureFailedHandler:^(NSError *error) {
NSLog(@"oh no!");
}
];
如果您想在您的应用中播放视频,您需要调用 Nimbb 服务的 Live/Play 函数。以下是一个您可以使用的示例代码
NSURL *url= [NSURL URLWithString:[NSString stringWithFormat:@"http://api.nimbb.com/Live/Play.aspx?guid=%@&key=%@",
@"NIMBBVIDEOGUID", @"YOURPUBLICKEY"]];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayerController.controlStyle=MPMovieControlStyleDefault;
moviePlayerController.shouldAutoplay=YES;
[moviePlayerController setFullscreen:YES animated:YES];
您可以选择并测试示例项目。请确保将相应的项目 Bundle ID 添加到您的 Nimbb 账户的设置中(选择 "iOS 应用")。修改文件 ViewController.m 中的 kPublicKey 的值以匹配您的 公钥。在实体设备上运行以使用摄像头进行录制。