From 353f2c80f4d21dbed9f204aea295494abacc3350 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Thu, 7 Nov 2024 12:39:13 +0400 Subject: [PATCH] video limit ios side --- src/ios/CameraSessionManager.h | 2 +- src/ios/CameraSessionManager.m | 6 ++++-- src/ios/SimpleCameraPreview.m | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ios/CameraSessionManager.h b/src/ios/CameraSessionManager.h index 4d0a07f..96a79dc 100644 --- a/src/ios/CameraSessionManager.h +++ b/src/ios/CameraSessionManager.h @@ -12,7 +12,7 @@ - (BOOL) deviceHasUltraWideCamera; - (void) deallocSession; - (void) updateOrientation:(AVCaptureVideoOrientation)orientation; -- (void) startRecording:(NSURL *)fileURL recordingDelegate:(id)recordingDelegate; +- (void) startRecording:(NSURL *)fileURL recordingDelegate:(id)recordingDelegate videoDurationMs:(NSInteger)videoDuration; - (void) stopRecording; - (AVCaptureVideoOrientation) getCurrentOrientation:(UIInterfaceOrientation)toInterfaceOrientation; + (AVCaptureSessionPreset) calculateResolution:(NSInteger)targetSize; diff --git a/src/ios/CameraSessionManager.m b/src/ios/CameraSessionManager.m index 3f0c81e..4500985 100644 --- a/src/ios/CameraSessionManager.m +++ b/src/ios/CameraSessionManager.m @@ -239,14 +239,16 @@ - (void)switchCameraTo:(NSString*)cameraMode completion:(void (^)(BOOL success)) }); } -- (void)startRecording:(NSURL *)fileURL recordingDelegate:(id)recordingDelegate { +- (void)startRecording:(NSURL *)fileURL recordingDelegate:(id)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 diff --git a/src/ios/SimpleCameraPreview.m b/src/ios/SimpleCameraPreview.m index 5fa2b28..af7dbf7 100644 --- a/src/ios/SimpleCameraPreview.m +++ b/src/ios/SimpleCameraPreview.m @@ -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];