OperationNodeVideoBase.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // OperationNodeVideoBase.m
  3. // LenzCameraNativeModuleForRN
  4. //
  5. // Created by 王昭威 on 2023/1/25.
  6. //
  7. #import "OperationNodeVideoBase.h"
  8. #import "PCSBaseViewController.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. // [self updateButtonStatusByCurrentRecordingState];
  34. return YES;
  35. }
  36. - (void)stop{
  37. self.isRecording = NO;
  38. [self updateButtonStatusByCurrentRecordingState];
  39. if (!NSThread.isMainThread) {
  40. dispatch_async(dispatch_get_main_queue(), ^{
  41. // self.controller.albumButton.hidden = NO;
  42. // self.controller.savePhotoButton.hidden = NO;
  43. // self.controller.discardPhotoButton.hidden = NO;
  44. // self.controller.switchButton.hidden = NO;
  45. // UIView* list = (UIView*)self.controller.modeList;
  46. // self.controller.panGesture.enabled = YES;
  47. // list.userInteractionEnabled = YES;
  48. // [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
  49. //
  50. // self.controller.albumButton.alpha = 1;
  51. // self.controller.savePhotoButton.alpha = 1;
  52. // self.controller.discardPhotoButton.alpha = 1;
  53. // self.controller.switchButton.alpha = 1;
  54. // } completion:^(BOOL finished) {}];
  55. });
  56. }
  57. }
  58. #pragma mark - button
  59. - (void)takePhotoButtonTouched{
  60. BOOL updatedRecording = !self.isRecording;
  61. self.controller.isVideoStitchStopedWhenRecording = NO;
  62. self.isRecording = updatedRecording && [self start];
  63. self.controller.panGesture.enabled = !self.isRecording;
  64. self.controller.timerLabel.backgroundColor = !self.isRecording ? [UIColor clearColor] : [PCSThemeColorManager orange];
  65. [self updateTakePhotoButtonStatus];
  66. // UIView* list = (UIView*)self.controller.modeList;
  67. if(!self.isRecording){
  68. self.controller.isVideoStitchStopedWhenRecording = YES;
  69. [self updateButtonStatusByCurrentRecordingState];
  70. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  71. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  72. [self stop];
  73. });
  74. } else {
  75. [self stop];
  76. }
  77. }
  78. else{
  79. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  80. [self.controller.timerLabel updateWith:0];
  81. self.controller.timerLabel.padding = UIEdgeInsetsMake(0, 2.5, 0, 2.5);
  82. self.stitchTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
  83. // dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, (int64_t)1 * NSEC_PER_SEC);
  84. uint64_t duration = (uint64_t)(1.0 * NSEC_PER_SEC);
  85. __block NSInteger count = 0;
  86. dispatch_source_set_timer(self.stitchTimer, DISPATCH_TIME_NOW, duration, 0 * NSEC_PER_SEC);
  87. dispatch_source_set_event_handler(self.stitchTimer, ^{
  88. dispatch_async(dispatch_get_main_queue(), ^{
  89. if (!self.isRecording) {
  90. dispatch_source_cancel(self.stitchTimer);
  91. self.controller.timerLabel.hidden = YES;
  92. self.controller.modeLabel.hidden = NO;
  93. return;
  94. }
  95. if (count <= self.recTime) {
  96. self.controller.timerLabel.backgroundColor = [PCSThemeColorManager orange];
  97. [self.controller.timerLabel updateWith:count];
  98. NSLog(@"aaaaaaaaaaaaa%@", self.controller.timerLabel.text);
  99. self.controller.timerLabel.hidden = NO;
  100. self.controller.modeLabel.hidden = YES;
  101. self.controller.flashButton.hidden = YES;
  102. self.controller.ai_fullView.hidden = YES;
  103. self.controller.panoramOrientationGuideView.hidden = YES;
  104. count++;
  105. } else {
  106. [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"超过最大拼接时长,拼接结束"];
  107. self.controller.timerLabel.backgroundColor = [UIColor clearColor];
  108. [self.controller.timerLabel updateWith:0];
  109. self.controller.timerLabel.hidden = YES;
  110. self.controller.modeLabel.hidden = NO;
  111. self.controller.flashButton.hidden = NO;
  112. self.controller.ai_fullView.hidden = NO;
  113. self.controller.panoramOrientationGuideView.hidden = NO;
  114. self.controller.isVideoStitchStopedWhenRecording = YES;
  115. UIImage* img = self.isRecording ? [UIImage loadNamed:@"btn-stop-recording"] : [UIImage loadNamed:@"take-photo-btn"];
  116. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  117. dispatch_source_cancel(self.stitchTimer);
  118. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  119. [self stop];
  120. [self.controller stopVideoDataOutputing];
  121. });
  122. [SVProgressHUD dismissWithDelay:3 completion:^{
  123. }];
  124. }
  125. });
  126. });
  127. dispatch_resume(self.stitchTimer);
  128. }
  129. [self updateUI];
  130. }
  131. }
  132. - (void)updateUI{
  133. }
  134. #pragma mark - update UI
  135. - (void)updateButtonStatusByCurrentRecordingState{
  136. // if (!NSThread.isMainThread) {
  137. dispatch_async(dispatch_get_main_queue(), ^{
  138. // self.controller.panGesture.enabled = !self.isRecording;
  139. // self.controller.switchButton.enabled = !self.isRecording;
  140. // self.controller.savePhotoButton.enabled = !self.isRecording;
  141. // self.controller.discardPhotoButton.enabled = !self.isRecording;
  142. // self.controller.backButton.enabled = !self.isRecording;
  143. // self.controller.albumButton.enabled = !self.isRecording;
  144. self.controller.timerLabel.hidden = YES;
  145. self.controller.modeLabel.hidden = NO;
  146. // self.controller.numberOfImagesLabel.hidden = NO;
  147. });
  148. // }
  149. }
  150. #pragma mark - Accessor
  151. //- (void)setIsRecording:(BOOL)isRecording{
  152. // _isRecording = isRecording;
  153. // UIImage* img = isRecording ? [UIImage loadNamed:@"btn-stop-recording"] : [UIImage loadNamed:@"take-photo-btn"];
  154. // if (!NSThread.isMainThread) {
  155. // dispatch_async(dispatch_get_main_queue(), ^{
  156. //
  157. // [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  158. // });
  159. // }
  160. //}
  161. - (void)updateTakePhotoButtonStatus {
  162. UIImage* img = self.isRecording ? [UIImage loadNamed:@"btn-stop-recording"] : [UIImage loadNamed:@"take-photo-btn"];
  163. if (!NSThread.isMainThread) {
  164. dispatch_async(dispatch_get_main_queue(), ^{
  165. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  166. });
  167. } else {
  168. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  169. }
  170. if (!self.isRecording) {
  171. [self.controller.timerLabel updateWith:0];
  172. self.controller.flashButton.hidden = NO;
  173. self.controller.discardPhotoButton.hidden = NO;
  174. self.controller.savePhotoButton.hidden = NO;
  175. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  176. self.controller.switchButton.hidden = YES;
  177. } else {
  178. self.controller.switchButton.hidden = NO;
  179. }
  180. self.controller.modeList.hidden = NO;
  181. self.controller.ablumImageView.hidden = NO;
  182. // self.controller.numberOfImagesLabel.hidden = NO;
  183. } else {
  184. self.controller.flashButton.hidden = YES;
  185. self.controller.discardPhotoButton.hidden = YES;
  186. self.controller.savePhotoButton.hidden = YES;
  187. self.controller.switchButton.hidden = YES;
  188. self.controller.backButton.hidden = YES;
  189. self.controller.modeList.hidden = YES;
  190. self.controller.ablumImageView.hidden = YES;
  191. self.controller.numberOfImagesLabel.hidden = YES;
  192. }
  193. }
  194. @end