OperationNodeVideoBase.m 6.8 KB

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