OperationNodeVideoBase.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //
  2. // OperationNodeVideoBase.m
  3. // LenzCameraNativeModuleForRN
  4. //
  5. // Created by 王昭威 on 2023/1/25.
  6. //
  7. #import "PCSBaseViewController.h"
  8. #import "OperationNodeVideoBase.h"
  9. #import "PCSRoundButton.h"
  10. #import "TimerLabel.h"
  11. #import "PCSModeList.h"
  12. #import "PanoramaGuideView.h"
  13. #import "SVProgressHUD.h"
  14. @interface OperationNodeVideoBase()
  15. @property (nonatomic) dispatch_source_t stitchTimer;
  16. @end
  17. @implementation OperationNodeVideoBase
  18. - (instancetype)initWithController:(PCSBaseViewController *)controller{
  19. self = [super init];
  20. if(self){
  21. _controller = controller;
  22. _isRecording = NO;
  23. }
  24. return self;
  25. }
  26. #pragma mark - strategy
  27. - (void)discardPhotoResultButtonTouchUpInside{
  28. [self cleanOnCompleted:^{
  29. [self.controller dismissViewControllerAnimated:YES completion:^{}];
  30. }];
  31. }
  32. - (BOOL)start{
  33. return YES;
  34. }
  35. - (void)stop{
  36. self.isRecording = NO;
  37. [self updateButtonStatusByCurrentRecordingState];
  38. }
  39. #pragma mark - button
  40. - (void)takePhotoButtonTouched{
  41. BOOL updatedRecording = !self.isRecording;
  42. self.controller.isVideoStitchStopedWhenRecording = NO;
  43. self.isRecording = updatedRecording && [self start];
  44. if(self.isRecording){
  45. self.controller.panoramaGuideView.hidden = NO;
  46. if ([self.controller.panoramOrientationGuideView.delegate respondsToSelector:@selector(panoramDirDidChange)]) {
  47. [self.controller.panoramOrientationGuideView.delegate panoramDirDidChange];
  48. }
  49. }
  50. self.controller.panGesture.enabled = !self.isRecording;
  51. self.controller.timerLabel.backgroundColor = !self.isRecording ? [UIColor clearColor] : [PCSThemeColorManager orange];
  52. [self updateTakePhotoButtonStatus];
  53. if(!self.isRecording){
  54. self.controller.isVideoStitchStopedWhenRecording = YES;
  55. [self updateButtonStatusByCurrentRecordingState];
  56. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  57. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  58. [self stop];
  59. });
  60. } else {
  61. [self stop];
  62. }
  63. }
  64. else{
  65. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  66. [self.controller.timerLabel updateWith:0];
  67. self.controller.timerLabel.padding = UIEdgeInsetsMake(0, 2.5, 0, 2.5);
  68. self.stitchTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
  69. uint64_t duration = (uint64_t)(1.0 * NSEC_PER_SEC);
  70. __block NSInteger count = 0;
  71. dispatch_source_set_timer(self.stitchTimer, DISPATCH_TIME_NOW, duration, 0 * NSEC_PER_SEC);
  72. dispatch_source_set_event_handler(self.stitchTimer, ^{
  73. dispatch_async(dispatch_get_main_queue(), ^{
  74. if (!self.isRecording) {
  75. dispatch_source_cancel(self.stitchTimer);
  76. self.controller.timerLabel.hidden = YES;
  77. self.controller.modeLabel.hidden = NO;
  78. return;
  79. }
  80. if (self.recTime == 0 || count <= self.recTime) {
  81. self.controller.timerLabel.backgroundColor = [PCSThemeColorManager orange];
  82. [self.controller.timerLabel updateWith:count];
  83. self.controller.timerLabel.hidden = NO;
  84. self.controller.modeLabel.hidden = YES;
  85. self.controller.flashButton.hidden = YES;
  86. self.controller.ai_fullView.hidden = YES;
  87. self.controller.panoramOrientationGuideView.hidden = YES;
  88. count++;
  89. } else {
  90. [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"超过最大拼接时长,拼接结束"];
  91. self.controller.timerLabel.backgroundColor = [UIColor clearColor];
  92. [self.controller.timerLabel updateWith:0];
  93. self.controller.timerLabel.hidden = YES;
  94. self.controller.modeLabel.hidden = NO;
  95. self.controller.flashButton.hidden = NO;
  96. self.controller.ai_fullView.hidden = NO;
  97. self.controller.panoramOrientationGuideView.hidden = NO;
  98. self.controller.isVideoStitchStopedWhenRecording = YES;
  99. UIImage* img = self.isRecording ? [UIImage loadNamed:@"btn-stop-recording"] : [UIImage loadNamed:@"take-photo-btn"];
  100. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  101. dispatch_source_cancel(self.stitchTimer);
  102. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  103. [self stop];
  104. [self.controller stopVideoDataOutputing];
  105. });
  106. [SVProgressHUD dismissWithDelay:3 completion:^{
  107. }];
  108. }
  109. });
  110. });
  111. dispatch_resume(self.stitchTimer);
  112. }
  113. [self updateUI];
  114. }
  115. }
  116. - (void)updateUI{
  117. }
  118. #pragma mark - update UI
  119. - (void)updateButtonStatusByCurrentRecordingState{
  120. dispatch_async(dispatch_get_main_queue(), ^{
  121. self.controller.timerLabel.hidden = YES;
  122. self.controller.modeLabel.hidden = NO;
  123. });
  124. }
  125. #pragma mark - Accessor
  126. - (void)updateTakePhotoButtonStatus {
  127. UIImage* img = self.isRecording ? [UIImage loadNamed:@"btn-stop-recording"] : [UIImage loadNamed:@"take-photo-btn"];
  128. if (!NSThread.isMainThread) {
  129. dispatch_async(dispatch_get_main_queue(), ^{
  130. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  131. });
  132. } else {
  133. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  134. }
  135. if (!self.isRecording) {
  136. [self.controller.timerLabel updateWith:0];
  137. self.controller.flashButton.hidden = NO;
  138. self.controller.discardPhotoButton.hidden = NO;
  139. self.controller.savePhotoButton.hidden = NO;
  140. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  141. self.controller.switchButton.hidden = YES;
  142. } else {
  143. self.controller.switchButton.hidden = NO;
  144. }
  145. self.controller.modeList.hidden = NO;
  146. self.controller.ablumImageView.hidden = NO;
  147. } else {
  148. self.controller.flashButton.hidden = YES;
  149. self.controller.discardPhotoButton.hidden = YES;
  150. self.controller.savePhotoButton.hidden = YES;
  151. self.controller.switchButton.hidden = YES;
  152. self.controller.backButton.hidden = YES;
  153. self.controller.modeList.hidden = YES;
  154. self.controller.ablumImageView.hidden = YES;
  155. self.controller.numberOfImagesLabel.hidden = YES;
  156. }
  157. }
  158. @end