Skip to content

Commit

Permalink
add timer for video recording ios
Browse files Browse the repository at this point in the history
  • Loading branch information
YushraJewon committed Oct 21, 2024
1 parent 79c6ce6 commit 8945ad2
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/ios/SimpleCameraPreview.m
Original file line number Diff line number Diff line change
Expand Up @@ -367,26 +367,37 @@ - (void) initVideoCallback:(CDVInvokedUrlCommand*)command {
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

NSTimer *captureTimer;
- (void)startVideoCapture:(CDVInvokedUrlCommand*)command {
if (self.sessionManager != nil && !self.sessionManager.movieFileOutput.isRecording) {
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 {
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];
} else {
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Session not initialized or already recording"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
captureTimer = [NSTimer scheduledTimerWithTimeInterval:30.0
target:self
selector:@selector(stopVideoCapture:)
userInfo:nil
repeats:NO];
}
}

- (void)stopVideoCapture:(CDVInvokedUrlCommand*)command {
if (self.sessionManager != nil && self.sessionManager.movieFileOutput.isRecording) {
[self.sessionManager stopRecording];
if (self.sessionManager == nil || !self.sessionManager.movieFileOutput.isRecording) {
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Session not initialized or not recording"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} else {
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Session not initialized or not recording"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.sessionManager stopRecording];
if (captureTimer != nil) {
[captureTimer invalidate];
captureTimer = nil;
}
}
}

Expand Down

0 comments on commit 8945ad2

Please sign in to comment.