From f591ce99772bfdf75f0d468b19301c2c6c8d39cd Mon Sep 17 00:00:00 2001 From: YushraJewon Date: Mon, 21 Oct 2024 15:07:51 +0400 Subject: [PATCH] adjust ifs --- src/ios/SimpleCameraPreview.m | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/ios/SimpleCameraPreview.m b/src/ios/SimpleCameraPreview.m index 3dcde0a..95867eb 100644 --- a/src/ios/SimpleCameraPreview.m +++ b/src/ios/SimpleCameraPreview.m @@ -369,22 +369,34 @@ - (void) initVideoCallback:(CDVInvokedUrlCommand*)command { NSTimer *captureTimer; - (void)startVideoCapture:(CDVInvokedUrlCommand*)command { - if (self.sessionManager == nil || self.sessionManager.movieFileOutput.isRecording) { - CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Session not initialized or already recording"]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - } else { + if (self.sessionManager != nil && !self.sessionManager.movieFileOutput.isRecording) { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); NSString *libraryDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"NoCloud"]; NSString* uniqueFileName = [NSString stringWithFormat:@"%@.mp4",[[NSUUID UUID] UUIDString]]; NSString *dataPath = [libraryDirectory stringByAppendingPathComponent:uniqueFileName]; NSURL *fileURL = [NSURL fileURLWithPath:dataPath]; - [self.sessionManager startRecording:fileURL recordingDelegate:self]; captureTimer = [NSTimer scheduledTimerWithTimeInterval:30.0 - target:self - selector:@selector(stopVideoCapture:) - userInfo:nil - repeats:NO]; + target:self + selector:@selector(stopVideoCapture:) + userInfo:nil + repeats:NO]; + } else { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Session not initialized or already recording"]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + } +} + +- (void)stopVideoCapture:(CDVInvokedUrlCommand*)command { + if (self.sessionManager != nil && self.sessionManager.movieFileOutput.isRecording) { + [self.sessionManager stopRecording]; + if (captureTimer != nil) { + [captureTimer invalidate]; + captureTimer = nil; + } + } else { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Session not initialized or not recording"]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } }