Skip to content

Commit

Permalink
remove timer from simpleCameraPreview and add it on cameraSessionManager
Browse files Browse the repository at this point in the history
  • Loading branch information
YushraJewon committed Oct 29, 2024
1 parent b646c69 commit a6f5d16
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/ios/CameraSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
@property (nonatomic) AVCaptureVideoDataOutput *dataOutput;
@property (nonatomic, weak) id delegate;
@property (nonatomic) AVCaptureMovieFileOutput *movieFileOutput;
@property (nonatomic) NSTimer *videoTimer;
@end
9 changes: 9 additions & 0 deletions src/ios/CameraSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,22 @@ - (void)startRecording:(NSURL *)fileURL recordingDelegate:(id<AVCaptureFileOutpu
connection.videoOrientation = [self getCurrentOrientation];
}
[self.movieFileOutput startRecordingToOutputFileURL:fileURL recordingDelegate:recordingDelegate];
_videoTimer = [NSTimer scheduledTimerWithTimeInterval:30.0
target:self
selector:@selector(stopRecording)
userInfo:nil
repeats:NO];
}
}

- (void)stopRecording {
if (self.movieFileOutput.isRecording) {
[self.movieFileOutput stopRecording];
}
if (_videoTimer != nil) {
[_videoTimer invalidate];
_videoTimer = nil;
}
}

- (BOOL)deviceHasUltraWideCamera {
Expand Down
10 changes: 0 additions & 10 deletions src/ios/SimpleCameraPreview.m
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ - (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) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
Expand All @@ -376,11 +375,6 @@ - (void)startVideoCapture:(CDVInvokedUrlCommand*)command {
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];
} else {
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Session not initialized or already recording"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
Expand All @@ -390,10 +384,6 @@ - (void)startVideoCapture:(CDVInvokedUrlCommand*)command {
- (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 a6f5d16

Please sign in to comment.