Skip to content

Commit

Permalink
video limit ios side
Browse files Browse the repository at this point in the history
  • Loading branch information
parveshneedhoo committed Nov 7, 2024
1 parent ec4aa14 commit 353f2c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ios/CameraSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- (BOOL) deviceHasUltraWideCamera;
- (void) deallocSession;
- (void) updateOrientation:(AVCaptureVideoOrientation)orientation;
- (void) startRecording:(NSURL *)fileURL recordingDelegate:(id<AVCaptureFileOutputRecordingDelegate>)recordingDelegate;
- (void) startRecording:(NSURL *)fileURL recordingDelegate:(id<AVCaptureFileOutputRecordingDelegate>)recordingDelegate videoDurationMs:(NSInteger)videoDuration;
- (void) stopRecording;
- (AVCaptureVideoOrientation) getCurrentOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
+ (AVCaptureSessionPreset) calculateResolution:(NSInteger)targetSize;
Expand Down
6 changes: 4 additions & 2 deletions src/ios/CameraSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,16 @@ - (void)switchCameraTo:(NSString*)cameraMode completion:(void (^)(BOOL success))
});
}

- (void)startRecording:(NSURL *)fileURL recordingDelegate:(id<AVCaptureFileOutputRecordingDelegate>)recordingDelegate {
- (void)startRecording:(NSURL *)fileURL recordingDelegate:(id<AVCaptureFileOutputRecordingDelegate>)recordingDelegate videoDurationMs:(NSInteger)videoDurationMs {
if (!self.movieFileOutput.isRecording) {
AVCaptureConnection *connection = [self.movieFileOutput connectionWithMediaType:AVMediaTypeVideo];
if ([connection isVideoOrientationSupported]) {
connection.videoOrientation = [self getCurrentOrientation];
}
[self.movieFileOutput startRecordingToOutputFileURL:fileURL recordingDelegate:recordingDelegate];
_videoTimer = [NSTimer scheduledTimerWithTimeInterval:30.0

NSInteger videoDurationInSec = videoDurationMs / 1000;
_videoTimer = [NSTimer scheduledTimerWithTimeInterval:videoDurationInSec
target:self
selector:@selector(stopRecording)
userInfo:nil
Expand Down
5 changes: 4 additions & 1 deletion src/ios/SimpleCameraPreview.m
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,16 @@ - (void) initVideoCallback:(CDVInvokedUrlCommand*)command {
}

- (void)startVideoCapture:(CDVInvokedUrlCommand*)command {
NSDictionary* config = command.arguments[0];
NSInteger videoDuration = ((NSNumber*)config[@"videoDurationMs"]).intValue;

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];
[self.sessionManager startRecording:fileURL recordingDelegate:self videoDurationMs:videoDuration];
} else {
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Session not initialized or already recording"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
Expand Down

0 comments on commit 353f2c8

Please sign in to comment.