Commit ab3ef2c9f28e6896242c4849de947ac040f8f044

Authored by liushiyu
1 parent 807d6b6b

0.1.7

CNLiveAVCamera.podspec
... ... @@ -8,7 +8,7 @@
8 8  
9 9 Pod::Spec.new do |s|
10 10 s.name = 'CNLiveAVCamera'
11   - s.version = '0.1.6'
  11 + s.version = '0.1.7'
12 12 s.summary = '自定义相机'
13 13  
14 14 # This description is used to generate tags and improve search results.
... ...
CNLiveAVCamera/Classes/XFCameraController.m
... ... @@ -529,7 +529,7 @@ typedef void(^PropertyChangeBlock)(AVCaptureDevice *captureDevice);
529 529 [_playerLayer removeFromSuperlayer];
530 530 _playerLayer = nil;
531 531  
532   - [weakSelf cropWithVideoUrlStr:weakSelf.videoURL start:0 end:weakSelf.currentVideoTimeLength completion:^(NSURL *outputURL, Float64 videoDuration, BOOL isSuccess) {
  532 + [weakSelf cropWithVideoUrlStr:weakSelf.videoURL start:0 end:weakSelf.currentVideoTimeLength completion:^(NSURL *outputURL, Float64 videoDuration, BOOL isSuccess, NSError * error) {
533 533  
534 534 if (isSuccess)
535 535 {
... ... @@ -593,6 +593,7 @@ typedef void(^PropertyChangeBlock)(AVCaptureDevice *captureDevice);
593 593 weakSelf.videoURL = nil;
594 594 [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
595 595 sender.enabled = YES;
  596 + if (weakSelf.zxshootCompletionBlock) weakSelf.zxshootCompletionBlock(nil,nil, 0, nil, error);
596 597 }
597 598 }];
598 599 }
... ... @@ -1764,7 +1765,7 @@ typedef void(^PropertyChangeBlock)(AVCaptureDevice *captureDevice);
1764 1765  
1765 1766 #pragma mark - 截取视频方法
1766 1767  
1767   -- (void)cropWithVideoUrlStr:(NSURL *)videoUrl start:(CGFloat)startTime end:(CGFloat)endTime completion:(void (^)(NSURL *outputURL, Float64 videoDuration, BOOL isSuccess))completionHandle
  1768 +- (void)cropWithVideoUrlStr:(NSURL *)videoUrl start:(CGFloat)startTime end:(CGFloat)endTime completion:(void (^)(NSURL *outputURL, Float64 videoDuration, BOOL isSuccess, NSError * error))completionHandle
1768 1769 {
1769 1770 AVURLAsset *asset =[[AVURLAsset alloc] initWithURL:videoUrl options:nil];
1770 1771  
... ... @@ -1805,22 +1806,22 @@ typedef void(^PropertyChangeBlock)(AVCaptureDevice *captureDevice);
1805 1806 case AVAssetExportSessionStatusFailed:
1806 1807 {
1807 1808 NSLog(@"合成失败:%@", [[exportSession error] description]);
1808   - completionHandle(outputURL, endTime, NO);
  1809 + completionHandle(outputURL, endTime, NO,[exportSession error]);
1809 1810 }
1810 1811 break;
1811 1812 case AVAssetExportSessionStatusCancelled:
1812 1813 {
1813   - completionHandle(outputURL, endTime, NO);
  1814 + completionHandle(outputURL, endTime, NO,[exportSession error]?[exportSession error]:nil);
1814 1815 }
1815 1816 break;
1816 1817 case AVAssetExportSessionStatusCompleted:
1817 1818 {
1818   - completionHandle(outputURL, endTime, YES);
  1819 + completionHandle(outputURL, endTime, YES,[exportSession error]?[exportSession error]:nil);
1819 1820 }
1820 1821 break;
1821 1822 default:
1822 1823 {
1823   - completionHandle(outputURL, endTime, NO);
  1824 + completionHandle(outputURL, endTime, NO,[exportSession error]?[exportSession error]:nil);
1824 1825 } break;
1825 1826 }
1826 1827 }];
... ...
Example/CNLiveAVCamera/CNLiveViewController.m
... ... @@ -31,6 +31,7 @@
31 31  
32 32 - (void)takeToXFPhoto
33 33 {
  34 + /*
34 35 XFCameraController *cameraController = [[XFCameraController alloc] init];
35 36 cameraController.isCanShootVideo = YES;
36 37 NSString *tempName = [NSString stringWithFormat:@"%@/",@"name"];
... ... @@ -82,6 +83,29 @@
82 83 };
83 84  
84 85 [self presentViewController:cameraController animated:YES completion:nil];
  86 + */
  87 + XFCameraController *cameraController = [[XFCameraController alloc] init];
  88 + cameraController.isCanShootVideo = YES;
  89 + cameraController.outPutPath = [self chatFilePathByUserId];
  90 + cameraController.modalPresentationStyle = UIModalPresentationFullScreen;
  91 + __weak XFCameraController *weakCameraController = cameraController;
  92 + cameraController.takePhotosCompletionBlock = ^(UIImage *image, NSError *error) {
  93 + if (!error) {
  94 +
  95 + }
  96 + };
  97 +
  98 + cameraController.zxshootCompletionBlock = ^(PHAsset *asset, NSURL *videoUrl, CGFloat videoTimeLength, UIImage *thumbnailImage, NSError *error) {
  99 + if (!error) {
  100 +
  101 + }else
  102 + {
  103 + NSLog(@"拍摄视频失败");
  104 + }
  105 +
  106 + };
  107 +
  108 + [self presentViewController:cameraController animated:YES completion:NULL];
85 109 }
86 110  
87 111 - (void)takeBtnAction:(UIButton *)sender {
... ... @@ -91,6 +115,26 @@
91 115  
92 116 }
93 117  
  118 +- (nullable NSString *)chatFilePathByUserId{
  119 +
  120 + NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"1234"];
  121 +
  122 + NSFileManager *fileManager = [NSFileManager defaultManager];
  123 + BOOL isDir = NO;
  124 +
  125 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  126 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  127 +
  128 + if ( !(isDir == YES && existed == YES) ) {
  129 +
  130 + // 在 temp 目录下创建一临时文件
  131 + [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  132 + }
  133 +
  134 + return filePath;
  135 +
  136 +}
  137 +
94 138  
95 139 - (void)didReceiveMemoryWarning
96 140 {
... ...