Skip to content

Commit

Permalink
adjust ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
YushraJewon committed Oct 21, 2024
1 parent 8945ad2 commit f591ce9
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/ios/SimpleCameraPreview.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand Down

0 comments on commit f591ce9

Please sign in to comment.