CNLiveViewController.m
2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// CNLiveViewController.m
// CNLiveAVCamera
//
// Created by jyyjkt on 05/05/2019.
// Copyright (c) 2019 jyyjkt. All rights reserved.
//
#import "CNLiveViewController.h"
#import "XFCameraController.h"
@interface CNLiveViewController ()
@end
@implementation CNLiveViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *takeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
takeBtn.frame = CGRectMake(0, 0, 150, 150);
[takeBtn setBackgroundColor:[UIColor yellowColor]];
[self.view addSubview:takeBtn];
[takeBtn addTarget:self action:@selector(takeBtnAction:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)takeToXFPhoto
{
XFCameraController *cameraController = [[XFCameraController alloc] init];
cameraController.isCanShootVideo = YES;
NSString *tempName = [NSString stringWithFormat:@"%@/",@"name"];
NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:tempName];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDir = NO;
// fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
if ( !(isDir == YES && existed == YES) ) {
// 在 temp 目录下创建一临时文件
[fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
}
cameraController.outPutPath = @"";
__weak XFCameraController *weakCameraController = cameraController;
__weak typeof(self) weakSelf = self;
//拍照完成
cameraController.takePhotosCompletionBlock = ^(UIImage *image, NSError *error) {
NSLog(@"takePhotosCompletionBlock");
dispatch_async(dispatch_get_main_queue(), ^{
[weakCameraController dismissViewControllerAnimated:YES completion:nil];
});
};
//录制完成
cameraController.zxshootCompletionBlock = ^(PHAsset *asset, NSURL *videoUrl, CGFloat videoTimeLength, UIImage *thumbnailImage, NSError *error) {
NSLog(@"shootCompletionBlock");
if (!error) {
dispatch_async(dispatch_get_main_queue(), ^{
[weakCameraController dismissViewControllerAnimated:YES completion:nil];
});
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"录制失败");
});
}
};
[self presentViewController:cameraController animated:YES completion:nil];
}
- (void)takeBtnAction:(UIButton *)sender {
[self takeToXFPhoto];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end