OperationNodeVideoBase.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. if ([self.controller.panoramOrientationGuideView.delegate respondsToSelector:@selector(panoramDirDidChange)]) {
  46. [self.controller.panoramOrientationGuideView.delegate panoramDirDidChange];
  47. }
  48. }
  49. self.controller.panGesture.enabled = !self.isRecording;
  50. self.controller.timerLabel.backgroundColor = !self.isRecording ? [UIColor clearColor] : [PCSThemeColorManager orange];
  51. [self updateTakePhotoButtonStatus];
  52. if(!self.isRecording){
  53. self.controller.isVideoStitchStopedWhenRecording = YES;
  54. [self updateButtonStatusByCurrentRecordingState];
  55. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  56. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  57. [self stop];
  58. });
  59. } else {
  60. [self stop];
  61. }
  62. }
  63. else{
  64. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  65. [self.controller.timerLabel updateWith:0];
  66. self.controller.timerLabel.padding = UIEdgeInsetsMake(0, 2.5, 0, 2.5);
  67. self.stitchTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
  68. uint64_t duration = (uint64_t)(1.0 * NSEC_PER_SEC);
  69. __block NSInteger count = 0;
  70. dispatch_source_set_timer(self.stitchTimer, DISPATCH_TIME_NOW, duration, 0 * NSEC_PER_SEC);
  71. dispatch_source_set_event_handler(self.stitchTimer, ^{
  72. dispatch_async(dispatch_get_main_queue(), ^{
  73. if (!self.isRecording) {
  74. dispatch_source_cancel(self.stitchTimer);
  75. self.controller.timerLabel.hidden = YES;
  76. self.controller.modeLabel.hidden = NO;
  77. return;
  78. }
  79. if (self.recTime == 0 || count <= self.recTime) {
  80. self.controller.timerLabel.backgroundColor = [PCSThemeColorManager orange];
  81. [self.controller.timerLabel updateWith:count];
  82. self.controller.timerLabel.hidden = NO;
  83. self.controller.modeLabel.hidden = YES;
  84. self.controller.flashButton.hidden = YES;
  85. self.controller.ai_fullView.hidden = YES;
  86. self.controller.panoramOrientationGuideView.hidden = YES;
  87. count++;
  88. } else {
  89. [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"超过最大拼接时长,拼接结束"];
  90. self.controller.timerLabel.backgroundColor = [UIColor clearColor];
  91. [self.controller.timerLabel updateWith:0];
  92. self.controller.timerLabel.hidden = YES;
  93. self.controller.modeLabel.hidden = NO;
  94. self.controller.flashButton.hidden = NO;
  95. self.controller.ai_fullView.hidden = NO;
  96. self.controller.panoramOrientationGuideView.hidden = NO;
  97. self.controller.isVideoStitchStopedWhenRecording = YES;
  98. UIImage* img = self.isRecording ? [UIImage loadNamed:@"btn-stop-recording"] : [UIImage loadNamed:@"take-photo-btn"];
  99. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  100. dispatch_source_cancel(self.stitchTimer);
  101. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  102. [self stop];
  103. [self.controller stopVideoDataOutputing];
  104. });
  105. [SVProgressHUD dismissWithDelay:3 completion:^{
  106. }];
  107. }
  108. });
  109. });
  110. dispatch_resume(self.stitchTimer);
  111. }
  112. [self updateUI];
  113. }
  114. }
  115. - (void)updateUI{
  116. }
  117. #pragma mark - update UI
  118. - (void)updateButtonStatusByCurrentRecordingState{
  119. dispatch_async(dispatch_get_main_queue(), ^{
  120. self.controller.timerLabel.hidden = YES;
  121. self.controller.modeLabel.hidden = NO;
  122. });
  123. }
  124. #pragma mark - Accessor
  125. - (void)updateTakePhotoButtonStatus {
  126. UIImage* img = self.isRecording ? [UIImage loadNamed:@"btn-stop-recording"] : [UIImage loadNamed:@"take-photo-btn"];
  127. if (!NSThread.isMainThread) {
  128. dispatch_async(dispatch_get_main_queue(), ^{
  129. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  130. });
  131. } else {
  132. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  133. }
  134. if (!self.isRecording) {
  135. [self.controller.timerLabel updateWith:0];
  136. self.controller.flashButton.hidden = NO;
  137. self.controller.discardPhotoButton.hidden = NO;
  138. self.controller.savePhotoButton.hidden = NO;
  139. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  140. self.controller.switchButton.hidden = YES;
  141. } else {
  142. self.controller.switchButton.hidden = NO;
  143. }
  144. self.controller.modeList.hidden = NO;
  145. self.controller.ablumImageView.hidden = NO;
  146. } else {
  147. self.controller.flashButton.hidden = YES;
  148. self.controller.discardPhotoButton.hidden = YES;
  149. self.controller.savePhotoButton.hidden = YES;
  150. self.controller.switchButton.hidden = YES;
  151. self.controller.backButton.hidden = YES;
  152. self.controller.modeList.hidden = YES;
  153. self.controller.ablumImageView.hidden = YES;
  154. self.controller.numberOfImagesLabel.hidden = YES;
  155. }
  156. }
  157. @end