PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Dependencies/CaptureCamera/CaptureViewController/CaptureViewController.m

https://gitlab.com/Mr.Tomato/VideoEffects
Objective C | 729 lines | 536 code | 137 blank | 56 comment | 32 complexity | 7c633d78706860ada4d8aa1f5deaa326 MD5 | raw file
  1. #import "CaptureViewController.h"
  2. #import <QuartzCore/QuartzCore.h>
  3. #import "ProgressBar.h"
  4. #import "CaptureToolKit.h"
  5. #import "DeleteButton.h"
  6. #import "DDHTimerControl.h"
  7. #import <MobileCoreServices/UTCoreTypes.h>
  8. #import <MediaPlayer/MediaPlayer.h>
  9. #define TIMER_INTERVAL 0.05f
  10. #define TAG_ALERTVIEW_CLOSE_CONTROLLER 10086
  11. @interface CaptureViewController ()
  12. {
  13. }
  14. @property (nonatomic, assign) BOOL debugMode;
  15. @property (nonatomic, strong) UIView *leftEyeView;
  16. @property (nonatomic, strong) UIView *rightEyeView;
  17. @property (nonatomic, strong) UIView *mouthView;
  18. @property (nonatomic, strong) UIView *faceView;
  19. @property (strong, nonatomic) UIView *maskView;
  20. @property (strong, nonatomic) CameraRecorder *recorder;
  21. @property (strong, nonatomic) ProgressBar *progressBar;
  22. @property (strong, nonatomic) DeleteButton *deleteButton;
  23. @property (strong, nonatomic) UIButton *okButton;
  24. @property (strong, nonatomic) UIButton *closeButton;
  25. @property (strong, nonatomic) UIButton *switchButton;
  26. @property (strong, nonatomic) UIButton *settingButton;
  27. @property (strong, nonatomic) UIButton *recordButton;
  28. @property (strong, nonatomic) UIButton *flashButton;
  29. @property (assign, nonatomic) BOOL initalized;
  30. @property (assign, nonatomic) BOOL isProcessingData;
  31. @property (strong, nonatomic) UIView *preview;
  32. @property (strong, nonatomic) UIImageView *focusRectView;
  33. @property (nonatomic, strong) DDHTimerControl *timerControl;
  34. @end
  35. @implementation CaptureViewController
  36. #pragma mark - CameraRecorderDelegate
  37. - (void)didStartCurrentRecording:(NSURL *)fileURL
  38. {
  39. NSLog(@"正在录制视频: %@", fileURL);
  40. [self.progressBar addProgressView];
  41. [_progressBar stopShining];
  42. [_deleteButton setButtonStyle:DeleteButtonStyleNormal];
  43. self.timerControl.hidden = NO;
  44. }
  45. - (void)didFinishCurrentRecording:(NSURL *)outputFileURL duration:(CGFloat)videoDuration totalDuration:(CGFloat)totalDuration error:(NSError *)error
  46. {
  47. if (error)
  48. {
  49. NSLog(@"录制视频错误:%@", error);
  50. NSString *success = GBLocalizedString(@"Failed");
  51. ProgressBarDismissLoading(success);
  52. }
  53. else
  54. {
  55. NSLog(@"录制视频完成: %@", outputFileURL);
  56. NSString *success = GBLocalizedString(@"Success");
  57. ProgressBarDismissLoading(success);
  58. }
  59. [_progressBar startShining];
  60. self.isProcessingData = NO;
  61. self.timerControl.hidden = YES;
  62. if (totalDuration >= MAX_VIDEO_DUR)
  63. {
  64. self.timerControl.minutesOrSeconds = 0;
  65. [self pressOKButton];
  66. }
  67. else
  68. {
  69. self.timerControl.minutesOrSeconds = ((NSInteger) (MAX_VIDEO_DUR - totalDuration + 1));
  70. }
  71. }
  72. - (void)didRemoveCurrentVideo:(NSURL *)fileURL totalDuration:(CGFloat)totalDuration error:(NSError *)error
  73. {
  74. if (error)
  75. {
  76. NSLog(@"删除视频错误: %@", error);
  77. }
  78. else
  79. {
  80. NSLog(@"删除了视频: %@", fileURL);
  81. NSLog(@"现在视频长度: %f", totalDuration);
  82. }
  83. if ([_recorder getVideoCount] > 0)
  84. {
  85. [_deleteButton setStyle:DeleteButtonStyleNormal];
  86. }
  87. else
  88. {
  89. [_deleteButton setStyle:DeleteButtonStyleDisable];
  90. }
  91. _okButton.enabled = (totalDuration >= MIN_VIDEO_DUR);
  92. self.timerControl.minutesOrSeconds = ((NSInteger) (MAX_VIDEO_DUR - totalDuration + 1));
  93. }
  94. - (void)doingCurrentRecording:(NSURL *)outputFileURL duration:(CGFloat)videoDuration recordedVideosTotalDuration:(CGFloat)totalDuration
  95. {
  96. [_progressBar setLastProgressToWidth:videoDuration / MAX_VIDEO_DUR * _progressBar.frame.size.width];
  97. _okButton.enabled = (videoDuration + totalDuration >= MIN_VIDEO_DUR);
  98. self.timerControl.minutesOrSeconds = ((NSInteger) (MAX_VIDEO_DUR - totalDuration - videoDuration + 1));
  99. }
  100. - (void)didRecordingMultiVideosSuccess:(NSArray *)outputFilesURL
  101. {
  102. NSLog(@"RecordingMultiVideosSuccess: %@", outputFilesURL);
  103. NSString *success = GBLocalizedString(@"Success");
  104. ProgressBarDismissLoading(success);
  105. self.isProcessingData = NO;
  106. // Callback
  107. if (_callback)
  108. {
  109. self.callback(YES, outputFilesURL);
  110. }
  111. // Close
  112. [self dismissViewControllerAnimated:YES completion:nil];
  113. }
  114. - (void)didRecordingVideosSuccess:(NSURL *)outputFileURL
  115. {
  116. NSString *outputFile = [outputFileURL path];
  117. NSLog(@"didRecordingVideosSuccess: %@", outputFile);
  118. NSString *success = GBLocalizedString(@"Success");
  119. ProgressBarDismissLoading(success);
  120. self.isProcessingData = NO;
  121. // Callback
  122. if (_callback)
  123. {
  124. self.callback(YES, outputFileURL);
  125. }
  126. // Close
  127. [self dismissViewControllerAnimated:YES completion:nil];
  128. }
  129. - (void)didRecordingVideosError:(NSError*)error;
  130. {
  131. NSLog(@"didRecordingVideosError: %@", error.description);
  132. NSString *failed = GBLocalizedString(@"Failed");
  133. ProgressBarDismissLoading(failed);
  134. self.isProcessingData = NO;
  135. // Callback
  136. if (_callback)
  137. {
  138. self.callback(NO, @"The recording video is merge failed.");
  139. }
  140. // Close
  141. [self dismissViewControllerAnimated:YES completion:nil];
  142. }
  143. - (void)didTakePictureSuccess:(NSString *)outputFile
  144. {
  145. NSLog(@"didTakePictureSuccess: %@", outputFile);
  146. }
  147. - (void)didTakePictureError:(NSError*)error
  148. {
  149. NSLog(@"didTakePictureError: %@", error.description);
  150. }
  151. #pragma mark - View Life cycle
  152. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  153. {
  154. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  155. if (self)
  156. {
  157. // Custom initialization
  158. }
  159. return self;
  160. }
  161. - (id) init
  162. {
  163. self = [super init];
  164. if (self)
  165. {
  166. // Custom initialization
  167. }
  168. return self;
  169. }
  170. - (void)viewDidLoad
  171. {
  172. [super viewDidLoad];
  173. self.view.backgroundColor = color(16, 16, 16, 1);
  174. self.maskView = [self getMaskView];
  175. [self.view addSubview:_maskView];
  176. }
  177. - (void)viewDidAppear:(BOOL)animated
  178. {
  179. [super viewDidAppear:animated];
  180. if (_initalized)
  181. {
  182. return;
  183. }
  184. [self initPreview];
  185. [self initRecorder];
  186. [CaptureToolKit createVideoFolderIfNotExist];
  187. [self initProgressBar];
  188. [self initRecordButton];
  189. [self initDeleteButton];
  190. [self initOKButton];
  191. [self initTopLayout];
  192. [self initTimeControl];
  193. [self hideMaskView];
  194. self.initalized = YES;
  195. }
  196. - (void)initTimeControl
  197. {
  198. CGFloat len = 80;
  199. _timerControl = [[DDHTimerControl alloc] initWithFrame:CGRectMake((CGRectGetWidth(_progressBar.frame)-len)/2, CGRectGetMinY(self.progressBar.frame) - len, len, len)];
  200. _timerControl.translatesAutoresizingMaskIntoConstraints = NO;
  201. _timerControl.color = [UIColor greenColor];
  202. _timerControl.highlightColor = [UIColor yellowColor];
  203. _timerControl.minutesOrSeconds = MAX_VIDEO_DUR;
  204. _timerControl.maxValue = MAX_VIDEO_DUR;
  205. _timerControl.titleLabel.text = GBLocalizedString(@"Seconds");
  206. _timerControl.userInteractionEnabled = NO;
  207. [self.view addSubview:_timerControl];
  208. _timerControl.hidden = YES;
  209. }
  210. - (void)initPreview
  211. {
  212. self.preview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_SIZE.width, DEVICE_SIZE.width)];
  213. _preview.clipsToBounds = YES;
  214. [self.view insertSubview:_preview belowSubview:_maskView];
  215. }
  216. - (void)initRecorder
  217. {
  218. self.recorder = [[CameraRecorder alloc] init];
  219. _recorder.delegate = self;
  220. _recorder.previewLayer.frame = CGRectMake(0, 0, DEVICE_SIZE.width, DEVICE_SIZE.width);
  221. [self.preview.layer addSublayer:_recorder.previewLayer];
  222. }
  223. - (void)initProgressBar
  224. {
  225. self.progressBar = [ProgressBar getInstance];
  226. [CaptureToolKit setView:_progressBar toOriginY:DEVICE_SIZE.width];
  227. [self.view insertSubview:_progressBar belowSubview:_maskView];
  228. [_progressBar startShining];
  229. }
  230. - (void)initDeleteButton
  231. {
  232. if (_isProcessingData)
  233. {
  234. return;
  235. }
  236. self.deleteButton = [DeleteButton getInstance];
  237. [_deleteButton setButtonStyle:DeleteButtonStyleDisable];
  238. [CaptureToolKit setView:_deleteButton toOrigin:CGPointMake(15, self.view.frame.size.height - _deleteButton.frame.size.height - 10)];
  239. [_deleteButton addTarget:self action:@selector(pressDeleteButton) forControlEvents:UIControlEventTouchUpInside];
  240. CGPoint center = _deleteButton.center;
  241. center.y = _recordButton.center.y;
  242. _deleteButton.center = center;
  243. [self.view insertSubview:_deleteButton belowSubview:_maskView];
  244. }
  245. - (void)initRecordButton
  246. {
  247. CGFloat buttonW = 120.0f;
  248. self.recordButton = [[UIButton alloc] initWithFrame:CGRectMake((DEVICE_SIZE.width - buttonW) / 2.0, _progressBar.frame.origin.y + _progressBar.frame.size.height + 10, buttonW, buttonW)];
  249. [_recordButton setImage:[UIImage imageNamed:@"video_longvideo_btn_shot"] forState:UIControlStateNormal];
  250. [self.view insertSubview:_recordButton belowSubview:_maskView];
  251. // Tap Gesture
  252. UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @selector(longPressGestureRecognized:)];
  253. gesture.minimumPressDuration = 0.3;
  254. [_recordButton addGestureRecognizer: gesture];
  255. }
  256. - (void)initOKButton
  257. {
  258. CGFloat okButtonW = 50;
  259. self.okButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, okButtonW, okButtonW)];
  260. _okButton.enabled = NO;
  261. [_okButton setBackgroundImage:[UIImage imageNamed:@"record_icon_hook_normal_bg"] forState:UIControlStateNormal];
  262. [_okButton setBackgroundImage:[UIImage imageNamed:@"record_icon_hook_highlighted_bg"] forState:UIControlStateHighlighted];
  263. [_okButton setImage:[UIImage imageNamed:@"record_icon_hook_normal"] forState:UIControlStateNormal];
  264. [CaptureToolKit setView:_okButton toOrigin:CGPointMake(self.view.frame.size.width - okButtonW - 10, self.view.frame.size.height - okButtonW - 10)];
  265. [_okButton addTarget:self action:@selector(pressOKButton) forControlEvents:UIControlEventTouchUpInside];
  266. CGPoint center = _okButton.center;
  267. center.y = _recordButton.center.y;
  268. _okButton.center = center;
  269. [self.view insertSubview:_okButton belowSubview:_maskView];
  270. }
  271. - (void)initTopLayout
  272. {
  273. CGFloat buttonW = 35.0f;
  274. // 关闭
  275. self.closeButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 5, buttonW, buttonW)];
  276. [_closeButton setImage:[UIImage imageNamed:@"record_close_normal"] forState:UIControlStateNormal];
  277. [_closeButton setImage:[UIImage imageNamed:@"record_close_disable"] forState:UIControlStateDisabled];
  278. [_closeButton setImage:[UIImage imageNamed:@"record_close_highlighted"] forState:UIControlStateSelected];
  279. [_closeButton setImage:[UIImage imageNamed:@"record_close_highlighted"] forState:UIControlStateHighlighted];
  280. [_closeButton addTarget:self action:@selector(pressCloseButton) forControlEvents:UIControlEventTouchUpInside];
  281. [self.view insertSubview:_closeButton belowSubview:_maskView];
  282. // 前后摄像头转换
  283. self.switchButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - (buttonW + 10) * 2 - 10, 5, buttonW, buttonW)];
  284. [_switchButton setImage:[UIImage imageNamed:@"record_lensflip_normal"] forState:UIControlStateNormal];
  285. [_switchButton setImage:[UIImage imageNamed:@"record_lensflip_disable"] forState:UIControlStateDisabled];
  286. [_switchButton setImage:[UIImage imageNamed:@"record_lensflip_highlighted"] forState:UIControlStateSelected];
  287. [_switchButton setImage:[UIImage imageNamed:@"record_lensflip_highlighted"] forState:UIControlStateHighlighted];
  288. [_switchButton addTarget:self action:@selector(pressSwitchButton) forControlEvents:UIControlEventTouchUpInside];
  289. _switchButton.enabled = [_recorder isFrontCameraSupported];
  290. [self.view insertSubview:_switchButton belowSubview:_maskView];
  291. self.flashButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - (buttonW + 10), 5, buttonW, buttonW)];
  292. [_flashButton setImage:[UIImage imageNamed:@"record_flashlight_normal"] forState:UIControlStateNormal];
  293. [_flashButton setImage:[UIImage imageNamed:@"record_flashlight_disable"] forState:UIControlStateDisabled];
  294. [_flashButton setImage:[UIImage imageNamed:@"record_flashlight_highlighted"] forState:UIControlStateHighlighted];
  295. [_flashButton setImage:[UIImage imageNamed:@"record_flashlight_highlighted"] forState:UIControlStateSelected];
  296. _flashButton.enabled = _recorder.isTorchSupported;
  297. [_flashButton addTarget:self action:@selector(pressFlashButton) forControlEvents:UIControlEventTouchUpInside];
  298. [self.view insertSubview:_flashButton belowSubview:_maskView];
  299. _flashButton.enabled = !([_recorder isFrontCameraSupported] && [_recorder isFrontCamera]);
  300. // focus rect view
  301. self.focusRectView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 90, 90)];
  302. _focusRectView.image = [UIImage imageNamed:@"touch_focus_not"];
  303. _focusRectView.alpha = 0;
  304. [self.preview addSubview:_focusRectView];
  305. }
  306. - (void)pressCloseButton
  307. {
  308. if ([_recorder getVideoCount] > 0)
  309. {
  310. NSString *cancel = GBLocalizedString(@"Cancel");
  311. NSString *abandon = GBLocalizedString(@"Abandon");
  312. NSString *reminder = GBLocalizedString(@"Reminder");
  313. NSString *cancelVideoHint = GBLocalizedString(@"CancelVideoHint");
  314. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:reminder message:cancelVideoHint delegate:self cancelButtonTitle:cancel otherButtonTitles:abandon, nil];
  315. alertView.tag = TAG_ALERTVIEW_CLOSE_CONTROLLER;
  316. [alertView show];
  317. }
  318. else
  319. {
  320. [self dropTheVideo];
  321. }
  322. }
  323. - (void)pressSwitchButton
  324. {
  325. _switchButton.selected = !_switchButton.selected;
  326. // if (_switchButton.selected)
  327. {
  328. // 换成前摄像头
  329. if (_recorder.isFrontCamera)
  330. {
  331. [_recorder openTorch:NO];
  332. _flashButton.selected = NO;
  333. _flashButton.enabled = YES;
  334. }
  335. else
  336. {
  337. _flashButton.enabled = NO;
  338. }
  339. }
  340. // else
  341. // {
  342. // _flashButton.enabled = [_recorder isFrontCameraSupported] && [_recorder isFrontCamera];
  343. // }
  344. [_recorder switchCamera];
  345. }
  346. - (void)pressFlashButton
  347. {
  348. _flashButton.selected = !_flashButton.selected;
  349. [_recorder openTorch:_flashButton.selected];
  350. }
  351. - (void)pressDeleteButton
  352. {
  353. if (_deleteButton.style == DeleteButtonStyleNormal)
  354. {
  355. // 第一次按下删除按钮
  356. [_progressBar setLastProgressToStyle:ProgressBarProgressStyleDelete];
  357. [_deleteButton setButtonStyle:DeleteButtonStyleDelete];
  358. }
  359. else if (_deleteButton.style == DeleteButtonStyleDelete)
  360. {
  361. // 第二次按下删除按钮
  362. [self deleteLastVideo];
  363. [_progressBar deleteLastProgress];
  364. if ([_recorder getVideoCount] > 0)
  365. {
  366. [_deleteButton setButtonStyle:DeleteButtonStyleNormal];
  367. }
  368. else
  369. {
  370. [_deleteButton setButtonStyle:DeleteButtonStyleDisable];
  371. }
  372. }
  373. }
  374. - (void)pressOKButton
  375. {
  376. if (_isProcessingData)
  377. {
  378. return;
  379. }
  380. if (self.timerControl.minutesOrSeconds > 0)
  381. {
  382. // Progress bar
  383. NSString *title = GBLocalizedString(@"Processing");
  384. ProgressBarShowLoading(title);
  385. }
  386. [_recorder endVideoRecording];
  387. self.isProcessingData = YES;
  388. }
  389. - (UIImage*)capturePicture
  390. {
  391. UIImage *image = [_recorder capturePicture];
  392. UIView *flashView = [[UIView alloc] initWithFrame: _recorder.previewLayer.frame];
  393. [flashView setBackgroundColor:[UIColor whiteColor]];
  394. [flashView setAlpha:0.f];
  395. [[[self view] window] addSubview:flashView];
  396. [UIView animateWithDuration:.4f
  397. animations:^{
  398. [flashView setAlpha:1.f];
  399. [flashView setAlpha:0.f];
  400. }
  401. completion:^(BOOL finished){
  402. [flashView removeFromSuperview];
  403. }
  404. ];
  405. return image;
  406. }
  407. // 放弃本次视频,并且关闭页面
  408. - (void)dropTheVideo
  409. {
  410. [_recorder deleteAllVideo];
  411. if (_callback)
  412. {
  413. self.callback(NO, @"Abandon this recording video.");
  414. }
  415. [self dismissViewControllerAnimated:NO completion:nil];
  416. }
  417. // 删除最后一段视频
  418. - (void)deleteLastVideo
  419. {
  420. if ([_recorder getVideoCount] > 0)
  421. {
  422. [_recorder deleteLastVideo];
  423. }
  424. }
  425. - (void)hideMaskView
  426. {
  427. [UIView animateWithDuration:0.5f animations:^{
  428. CGRect frame = self.maskView.frame;
  429. frame.origin.y = self.maskView.frame.size.height;
  430. self.maskView.frame = frame;
  431. }];
  432. }
  433. - (UIView *)getMaskView
  434. {
  435. UIView *maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_SIZE.width, DEVICE_SIZE.height + DELTA_Y)];
  436. maskView.backgroundColor = color(30, 30, 30, 1);
  437. return maskView;
  438. }
  439. - (void)didReceiveMemoryWarning
  440. {
  441. [super didReceiveMemoryWarning];
  442. // Dispose of any resources that can be recreated.
  443. }
  444. - (BOOL)prefersStatusBarHidden
  445. {
  446. return YES;
  447. }
  448. - (void)showFocusRectAtPoint:(CGPoint)point
  449. {
  450. _focusRectView.alpha = 1.0f;
  451. _focusRectView.center = point;
  452. _focusRectView.transform = CGAffineTransformMakeScale(1.5f, 1.5f);
  453. [UIView animateWithDuration:0.2f animations:^{
  454. _focusRectView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
  455. } completion:^(BOOL finished)
  456. {
  457. CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
  458. animation.values = @[@0.5f, @1.0f, @0.5f, @1.0f, @0.5f, @1.0f];
  459. animation.duration = 0.5f;
  460. [_focusRectView.layer addAnimation:animation forKey:@"opacity"];
  461. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  462. [UIView animateWithDuration:0.3f animations:^{
  463. _focusRectView.alpha = 0;
  464. }];
  465. });
  466. }];
  467. // _focusRectView.transform = CGAffineTransformMakeScale(1.5f, 1.5f);
  468. // _focusRectView.center = point;
  469. // [UIView animateWithDuration:0.3f animations:^{
  470. // _focusRectView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
  471. // _focusRectView.alpha = 1.0f;
  472. // } completion:^(BOOL finished) {
  473. // [UIView animateWithDuration:0.1f animations:^{
  474. // _focusRectView.alpha = 0.0f;
  475. // }];
  476. // }];
  477. }
  478. //- (void)startProgressTimer
  479. //{
  480. // self.progressTimer = [NSTimer scheduledTimerWithTimeInterval:TIMER_INTERVAL target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];
  481. // self.progressCounter = 0;
  482. //}
  483. //
  484. //- (void)stopProgressTimer
  485. //{
  486. // [_progressTimer invalidate];
  487. // self.progressTimer = nil;
  488. //}
  489. //
  490. //- (void)onTimer:(NSTimer *)timer
  491. //{
  492. // self.progressCounter++;
  493. // [_progressBar setLastProgressToWidth:self.progressCounter * TIMER_INTERVAL / MAX_VIDEO_DUR * DEVICE_SIZE.width];
  494. //}
  495. #pragma mark - Tap Gesture
  496. // Add gesture by Johnny Xu
  497. - (void)longPressGestureRecognized:(UILongPressGestureRecognizer *) gesture
  498. {
  499. switch (gesture.state)
  500. {
  501. case UIGestureRecognizerStateBegan:
  502. {
  503. [self startRecording];
  504. break;
  505. }
  506. case UIGestureRecognizerStateEnded:
  507. {
  508. [self stopRecording];
  509. break;
  510. }
  511. default:
  512. break;
  513. }
  514. }
  515. #pragma mark - Video Recording
  516. - (void)startRecording
  517. {
  518. if (_isProcessingData)
  519. {
  520. return;
  521. }
  522. if (_deleteButton.style == DeleteButtonStyleDelete)
  523. {
  524. // 取消删除
  525. [_deleteButton setButtonStyle:DeleteButtonStyleNormal];
  526. [_progressBar setLastProgressToStyle:ProgressBarProgressStyleNormal];
  527. return;
  528. }
  529. self.isProcessingData = YES;
  530. NSString *filePath = [CaptureToolKit getVideoSaveFilePathString];
  531. [_recorder startRecordingToOutputFileURL:[NSURL fileURLWithPath:filePath]];
  532. }
  533. - (void)stopRecording
  534. {
  535. if (!_isProcessingData)
  536. {
  537. return;
  538. }
  539. // Progress bar
  540. NSString *title = GBLocalizedString(@"SavingVideo");
  541. ProgressBarShowLoading(title);
  542. [_recorder stopCurrentVideoRecording];
  543. }
  544. #pragma mark - UIAlertViewDelegate
  545. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  546. {
  547. switch (alertView.tag)
  548. {
  549. case TAG_ALERTVIEW_CLOSE_CONTROLLER:
  550. {
  551. switch (buttonIndex)
  552. {
  553. case 0:
  554. {
  555. break;
  556. }
  557. case 1:
  558. {
  559. [self dropTheVideo];
  560. break;
  561. }
  562. default:
  563. break;
  564. }
  565. }
  566. break;
  567. default:
  568. break;
  569. }
  570. }
  571. #pragma mark ---------rotate(only when this controller is presented, the code below effect)-------------
  572. //<iOS6
  573. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  574. {
  575. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  576. }
  577. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
  578. //iOS6+
  579. - (BOOL)shouldAutorotate
  580. {
  581. return NO;
  582. }
  583. - (NSUInteger)supportedInterfaceOrientations
  584. {
  585. return UIInterfaceOrientationMaskPortrait;
  586. }
  587. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
  588. {
  589. return UIInterfaceOrientationPortrait;
  590. }
  591. #endif
  592. @end