Commit e11be61fdcac96fb04d95a30e214811a0a996b37

Authored by 梁星国
1 parent e621f237

提交0.1.19_添加上传失败使用系统导出

CNLiveUploadManager.podspec
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 8
9 Pod::Spec.new do |s| 9 Pod::Spec.new do |s|
10 s.name = 'CNLiveUploadManager' 10 s.name = 'CNLiveUploadManager'
11 - s.version = '0.1.18' 11 + s.version = '0.1.19'
12 s.summary = '压缩上传,组件化中加入新参数加入outPath,不在直接取' 12 s.summary = '压缩上传,组件化中加入新参数加入outPath,不在直接取'
13 13
14 # This description is used to generate tags and improve search results. 14 # This description is used to generate tags and improve search results.
CNLiveUploadManager/Classes/CNLiveUploadManager.m
@@ -1061,13 +1061,34 @@ static CNLiveUploadManager *_uploadManager; @@ -1061,13 +1061,34 @@ static CNLiveUploadManager *_uploadManager;
1061 //不限制大小 1061 //不限制大小
1062 [strongSelf qnUploadVideoWithToken:token file:url.path progress:progress success:success failure:failure]; 1062 [strongSelf qnUploadVideoWithToken:token file:url.path progress:progress success:success failure:failure];
1063 } failure:^{ 1063 } failure:^{
1064 -  
1065 - dispatch_async(dispatch_get_main_queue(), ^{  
1066 - NSError *returnError = [NSError errorWithDomain:@"压缩失败" code:105 userInfo:@{NSLocalizedDescriptionKey:@"压缩失败,请重新获取"}];  
1067 - !failure ? : failure(nil,returnError);  
1068 - return; 1064 +
  1065 +#pragma mark - 更改七牛转码失败使用系统导出
  1066 + __strong typeof(weakSelf) strongSelf = weakSelf;
  1067 + [strongSelf zipSystemVideoWithAsset:asset outputPath:outputPath limitType:limitType progressCount:^(float progress) {
1069 1068
1070 - }); 1069 + NSLog(@"transCoding progress: %f", progress);
  1070 + BOOL isSucess = progress >= 1.0 ? YES : NO;
  1071 + !transcode ? : transcode(progress,isSucess);
  1072 +
  1073 + } success:^(NSURL *url) {
  1074 +
  1075 + __strong typeof(weakSelf) strongSelf = weakSelf;
  1076 + AVAsset *avAsset = [AVAsset assetWithURL:url];
  1077 + NSLog(@"转码后时长%f",[[NSNumber numberWithFloat:CMTimeGetSeconds(avAsset.duration)] floatValue]);
  1078 + NSLog(@"转码后数据大小%ldmb",[NSData dataWithContentsOfURL:url].length / (1024*1024));
  1079 + //不限制大小
  1080 + [strongSelf qnUploadVideoWithToken:token file:url.path progress:progress success:success failure:failure];
  1081 +
  1082 + } failure:^{
  1083 +
  1084 + dispatch_async(dispatch_get_main_queue(), ^{
  1085 + NSError *returnError = [NSError errorWithDomain:@"压缩失败" code:105 userInfo:@{NSLocalizedDescriptionKey:@"压缩失败,请重新获取"}];
  1086 + !failure ? : failure(nil,returnError);
  1087 + return;
  1088 +
  1089 + });
  1090 +
  1091 + }];
1071 1092
1072 }]; 1093 }];
1073 1094
@@ -1384,6 +1405,47 @@ static CNLiveUploadManager *_uploadManager; @@ -1384,6 +1405,47 @@ static CNLiveUploadManager *_uploadManager;
1384 1405
1385 } 1406 }
1386 1407
  1408 +
  1409 +
  1410 +#pragma mark - 系统视频压缩
  1411 +- (void )zipSystemVideoWithAsset:(id) asset outputPath:(NSString *)outputPath limitType:(AppPhototLimitType)limitType progressCount:(void(^)(float progress)) progressCount success:(void(^)(NSURL * url))success failure:(void(^)(void))failure {
  1412 +
  1413 + PHVideoRequestOptions* options = [[PHVideoRequestOptions alloc] init];
  1414 + options.version = PHVideoRequestOptionsVersionOriginal;
  1415 + options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
  1416 + options.networkAccessAllowed = YES;
  1417 + options.progressHandler = ^(double progress, NSError * _Nullable error, BOOL * _Nonnull stop, NSDictionary * _Nullable info) {
  1418 + NSLog(@"输出进度 = %f",progress);
  1419 + NSLog(@"transCoding progress: %f", progress);
  1420 + !progressCount ? : progressCount(progress);
  1421 +
  1422 + };
  1423 + __weak typeof(self) weakSelf = self;
  1424 + [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset* avasset, AVAudioMix* audioMix, NSDictionary* info){
  1425 + __strong typeof(weakSelf) strongSelf = weakSelf;
  1426 + if (!strongSelf) {
  1427 +
  1428 + !failure ? : failure();
  1429 + return;
  1430 + }
  1431 +
  1432 + NSLog(@"Info:\n%@",info);
  1433 + AVURLAsset *videoAsset = (AVURLAsset*)avasset;
  1434 + // NSLog(@"AVAsset URL: %@",myAsset.URL);
  1435 + [strongSelf startExportVideoWithVideoAsset:videoAsset presetName:AVAssetExportPresetMediumQuality outputPath:outputPath success:^(NSString *outputPath) {
  1436 + /// 不限制大小
  1437 + NSURL *url = [NSURL URLWithString:outputPath];
  1438 + !success ? : success(url);
  1439 +
  1440 + } failure:^(NSString *errorMessage, NSError *error) {
  1441 + !failure ? : failure();
  1442 + return;
  1443 + }];
  1444 + }];
  1445 +}
  1446 +
  1447 +
  1448 +
1387 /// (多张Asset - AssetArray - 压缩或原图 - 限制 - 筛选) 实现 1449 /// (多张Asset - AssetArray - 压缩或原图 - 限制 - 筛选) 实现
1388 - (void)afUploadLimitWithDic:(NSDictionary *)dic url:(NSString *)url type:(CNLiveUploadType)type assetArray:(NSMutableArray *)assetArray isOriginal:(BOOL) isOriginal limitType:(AppPhototLimitType)limitType progress:(progressHandlerBlock)progress success:(successBlock)success failure:(failureBlock)failure { 1450 - (void)afUploadLimitWithDic:(NSDictionary *)dic url:(NSString *)url type:(CNLiveUploadType)type assetArray:(NSMutableArray *)assetArray isOriginal:(BOOL) isOriginal limitType:(AppPhototLimitType)limitType progress:(progressHandlerBlock)progress success:(successBlock)success failure:(failureBlock)failure {
1389 1451
@@ -2139,7 +2201,7 @@ static CNLiveUploadManager *_uploadManager; @@ -2139,7 +2201,7 @@ static CNLiveUploadManager *_uploadManager;
2139 case AVAssetExportSessionStatusCompleted: { 2201 case AVAssetExportSessionStatusCompleted: {
2140 NSLog(@"AVAssetExportSessionStatusCompleted"); 2202 NSLog(@"AVAssetExportSessionStatusCompleted");
2141 if (success) { 2203 if (success) {
2142 - success(outputPath); 2204 + success(editOutputPath);
2143 } 2205 }
2144 } break; 2206 } break;
2145 case AVAssetExportSessionStatusFailed: { 2207 case AVAssetExportSessionStatusFailed: {