From 903916dcbe148b4682e661c2f6d62f74f12eca68 Mon Sep 17 00:00:00 2001 From: aman-geekybunch Date: Fri, 7 Mar 2025 14:57:22 +0530 Subject: [PATCH 1/7] Added option to save video to gallery and chose front facing camera --- src/ios/CDVCapture.h | 7 ++++++- src/ios/CDVCapture.m | 25 ++++++++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/ios/CDVCapture.h b/src/ios/CDVCapture.h index c7433a41..f6129aea 100644 --- a/src/ios/CDVCapture.h +++ b/src/ios/CDVCapture.h @@ -31,6 +31,7 @@ enum CDVCaptureError { CAPTURE_PERMISSION_DENIED = 4, CAPTURE_NOT_SUPPORTED = 20 }; + typedef NSUInteger CDVCaptureError; @interface CDVImagePicker : UIImagePickerController @@ -49,12 +50,14 @@ typedef NSUInteger CDVCaptureError; { CDVImagePicker* pickerController; BOOL inUse; + BOOL saveVideoToGallery; } @property BOOL inUse; +@property BOOL saveVideoToGallery; - (void)captureAudio:(CDVInvokedUrlCommand*)command; - (void)captureImage:(CDVInvokedUrlCommand*)command; - (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCallbackId:(NSString*)callbackId; -- (void)captureVideo:(CDVInvokedUrlCommand*)command; +- (void)captureVideo:(CDVInvokedUrlCommand*)command useFrontCamera:(BOOL)isFrontFacing saveToGallery:(BOOL)isSaveToGallery; - (CDVPluginResult*)processVideo:(NSString*)moviePath forCallbackId:(NSString*)callbackId; - (void)getMediaModes:(CDVInvokedUrlCommand*)command; - (void)getFormatData:(CDVInvokedUrlCommand*)command; @@ -117,3 +120,5 @@ typedef NSUInteger CDVCaptureError; - (NSString*)formatTime:(int)interval; - (void)updateTime; @end + + diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m index 3919848a..b59963c0 100644 --- a/src/ios/CDVCapture.m +++ b/src/ios/CDVCapture.m @@ -76,10 +76,11 @@ - (void)viewWillAppear:(BOOL)animated { @implementation CDVCapture @synthesize inUse; - +@synthesize saveVideoToGallery; - (void)pluginInitialize { self.inUse = NO; + self.saveVideoToGallery = FALSE; } - (void)captureAudio:(CDVInvokedUrlCommand*)command @@ -211,8 +212,9 @@ - (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCal return result; } -- (void)captureVideo:(CDVInvokedUrlCommand*)command +- (void)captureVideo:(CDVInvokedUrlCommand*)command useFrontCamera: (BOOL)isFrontFacing saveToGallery:(BOOL)isSaveToGallery { + self.saveVideoToGallery = isSaveToGallery; NSString* callbackId = command.callbackId; NSDictionary* options = [command argumentAtIndex:0]; @@ -282,6 +284,9 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command // pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; // pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto; } + if (isFrontFacing) { + pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; + } // CDVImagePicker specific property pickerController.callbackId = callbackId; pickerController.modalPresentationStyle = UIModalPresentationCurrentContext; @@ -293,13 +298,15 @@ - (CDVPluginResult*)processVideo:(NSString*)moviePath forCallbackId:(NSString*)c { // save the movie to photo album (only avail as of iOS 3.1) - /* don't need, it should automatically get saved - NSLog(@"can save %@: %d ?", moviePath, UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)); - if (&UIVideoAtPathIsCompatibleWithSavedPhotosAlbum != NULL && UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath) == YES) { - NSLog(@"try to save movie"); - UISaveVideoAtPathToSavedPhotosAlbum(moviePath, nil, nil, nil); - NSLog(@"finished saving movie"); - }*/ + /* don't need, it should automatically get saved*/ + if (self.saveVideoToGallery) { + NSLog(@"can save %@: %d ?", moviePath, UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)); + if (&UIVideoAtPathIsCompatibleWithSavedPhotosAlbum != NULL && UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath) == YES) { + NSLog(@"try to save movie"); + UISaveVideoAtPathToSavedPhotosAlbum(moviePath, nil, nil, nil); + NSLog(@"finished saving movie"); + } + } // create MediaFile object NSDictionary* fileDict = [self getMediaDictionaryFromPath:moviePath ofType:nil]; NSArray* fileArray = [NSArray arrayWithObject:fileDict]; From 46bc66e0797332fc054065b13261900fc3ba9421 Mon Sep 17 00:00:00 2001 From: aman-geekybunch Date: Fri, 7 Mar 2025 15:07:52 +0530 Subject: [PATCH 2/7] Added support for back and front camera Added support for back and front camera during video capture --- src/ios/CDVCapture.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m index b59963c0..227f075e 100644 --- a/src/ios/CDVCapture.m +++ b/src/ios/CDVCapture.m @@ -286,6 +286,8 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command useFrontCamera: (BOOL)isFron } if (isFrontFacing) { pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; + } else { + pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; } // CDVImagePicker specific property pickerController.callbackId = callbackId; From 28910043f6a3fccb2dc37ed7283bd9c2661b6080 Mon Sep 17 00:00:00 2001 From: aman-geekybunch Date: Fri, 7 Mar 2025 15:22:22 +0530 Subject: [PATCH 3/7] Changes to types/index.d file Added options frontFacing?: number; and saveToGallery?: number; so that we can use front camera to record video and save video to gallery --- src/ios/CDVCapture.h | 2 +- src/ios/CDVCapture.m | 11 ++++++++--- types/index.d.ts | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ios/CDVCapture.h b/src/ios/CDVCapture.h index f6129aea..30fec18c 100644 --- a/src/ios/CDVCapture.h +++ b/src/ios/CDVCapture.h @@ -57,7 +57,7 @@ typedef NSUInteger CDVCaptureError; - (void)captureAudio:(CDVInvokedUrlCommand*)command; - (void)captureImage:(CDVInvokedUrlCommand*)command; - (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCallbackId:(NSString*)callbackId; -- (void)captureVideo:(CDVInvokedUrlCommand*)command useFrontCamera:(BOOL)isFrontFacing saveToGallery:(BOOL)isSaveToGallery; +- (void)captureVideo:(CDVInvokedUrlCommand*)command; - (CDVPluginResult*)processVideo:(NSString*)moviePath forCallbackId:(NSString*)callbackId; - (void)getMediaModes:(CDVInvokedUrlCommand*)command; - (void)getFormatData:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m index 227f075e..fabf6006 100644 --- a/src/ios/CDVCapture.m +++ b/src/ios/CDVCapture.m @@ -212,9 +212,9 @@ - (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCal return result; } -- (void)captureVideo:(CDVInvokedUrlCommand*)command useFrontCamera: (BOOL)isFrontFacing saveToGallery:(BOOL)isSaveToGallery +- (void)captureVideo:(CDVInvokedUrlCommand*)command { - self.saveVideoToGallery = isSaveToGallery; + NSString* callbackId = command.callbackId; NSDictionary* options = [command argumentAtIndex:0]; @@ -226,6 +226,11 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command useFrontCamera: (BOOL)isFron // taking more than one video (limit) is only supported if provide own controls via cameraOverlayView property NSNumber* duration = [options objectForKey:@"duration"]; NSNumber* quality = [options objectForKey:@"quality"]; + NSNumber* frontFacing = [options objectForKey:@"frontFacing"]; + NSNumber* saveToGallery = [options objectForKey:@"saveToGallery"]; + if (saveToGallery == 1) { + self.saveVideoToGallery = TRUE; + } NSString* mediaType = nil; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { @@ -284,7 +289,7 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command useFrontCamera: (BOOL)isFron // pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; // pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto; } - if (isFrontFacing) { + if (frontFacing == 1) { pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; } else { pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; diff --git a/types/index.d.ts b/types/index.d.ts index 17f53858..27932aad 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -155,6 +155,10 @@ interface VideoOptions { limit?: number; /** The maximum duration of a video clip, in seconds. */ duration?: number; + /** Set 1 in case you want to use front facing camera for video capture. */ + frontFacing?: number; + /** Set 1 in case you want to use save video to gallery for video capture. */ + saveToGallery?: number; } /** Encapsulates a set of media capture parameters that a device supports. */ From 5466087151af9934489cc87b4b84d26598c9b821 Mon Sep 17 00:00:00 2001 From: aman-geekybunch Date: Thu, 13 Mar 2025 18:49:50 +0530 Subject: [PATCH 4/7] Set values to default set value to default for testing --- src/ios/CDVCapture.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m index fabf6006..6bba1121 100644 --- a/src/ios/CDVCapture.m +++ b/src/ios/CDVCapture.m @@ -231,6 +231,7 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command if (saveToGallery == 1) { self.saveVideoToGallery = TRUE; } + self.saveVideoToGallery = TRUE; NSString* mediaType = nil; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { @@ -289,11 +290,13 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command // pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; // pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto; } - if (frontFacing == 1) { + pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; + // NOTE:- comment out below code to work it based on conditions + /*if (frontFacing == 1) { pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; } else { pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; - } + }*/ // CDVImagePicker specific property pickerController.callbackId = callbackId; pickerController.modalPresentationStyle = UIModalPresentationCurrentContext; From b8661f91182bdc42eb49f8192391a345809e6afd Mon Sep 17 00:00:00 2001 From: aman-geekybunch Date: Thu, 13 Mar 2025 19:06:41 +0530 Subject: [PATCH 5/7] Made values default to TRUE is not sent Made values default to TRUE is not set --- src/ios/CDVCapture.m | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m index 6bba1121..34e6cca2 100644 --- a/src/ios/CDVCapture.m +++ b/src/ios/CDVCapture.m @@ -228,10 +228,21 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command NSNumber* quality = [options objectForKey:@"quality"]; NSNumber* frontFacing = [options objectForKey:@"frontFacing"]; NSNumber* saveToGallery = [options objectForKey:@"saveToGallery"]; - if (saveToGallery == 1) { + if(![[options allKeys] containsObject: @"frontFacing"]) { + // set to TRUE as default + frontFacing = [NSNumber numberWithInt: 1]; + } + if([[options allKeys] containsObject: @"saveToGallery"]) { + if (saveToGallery == 1) { + self.saveVideoToGallery = TRUE; + } else { + self.saveVideoToGallery = FALSE; + } + } else { + // set to TRUE as default self.saveVideoToGallery = TRUE; } - self.saveVideoToGallery = TRUE; + NSString* mediaType = nil; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { @@ -290,13 +301,12 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command // pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; // pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto; } - pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; // NOTE:- comment out below code to work it based on conditions - /*if (frontFacing == 1) { + if (frontFacing == 1) { pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; } else { pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; - }*/ + } // CDVImagePicker specific property pickerController.callbackId = callbackId; pickerController.modalPresentationStyle = UIModalPresentationCurrentContext; From 61a2fa9a21fe1b32910ee4a20e67214754f9f035 Mon Sep 17 00:00:00 2001 From: aman-geekybunch Date: Thu, 13 Mar 2025 20:15:49 +0530 Subject: [PATCH 6/7] comparison of bool comparison of bool fix --- src/ios/CDVCapture.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m index 34e6cca2..d4db3960 100644 --- a/src/ios/CDVCapture.m +++ b/src/ios/CDVCapture.m @@ -233,7 +233,7 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command frontFacing = [NSNumber numberWithInt: 1]; } if([[options allKeys] containsObject: @"saveToGallery"]) { - if (saveToGallery == 1) { + if ([saveToGallery boolValue]) { self.saveVideoToGallery = TRUE; } else { self.saveVideoToGallery = FALSE; @@ -301,8 +301,7 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command // pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; // pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto; } - // NOTE:- comment out below code to work it based on conditions - if (frontFacing == 1) { + if ([frontFacing boolValue]) { pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; } else { pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; From 7de190a474dc61d7298df4f10f916e8071ac05a5 Mon Sep 17 00:00:00 2001 From: aman-geekybunch Date: Thu, 13 Mar 2025 20:26:52 +0530 Subject: [PATCH 7/7] Changed true to YES Changed true to YES --- src/ios/CDVCapture.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m index d4db3960..9d585215 100644 --- a/src/ios/CDVCapture.m +++ b/src/ios/CDVCapture.m @@ -80,7 +80,7 @@ @implementation CDVCapture - (void)pluginInitialize { self.inUse = NO; - self.saveVideoToGallery = FALSE; + self.saveVideoToGallery = NO; } - (void)captureAudio:(CDVInvokedUrlCommand*)command @@ -234,13 +234,13 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command } if([[options allKeys] containsObject: @"saveToGallery"]) { if ([saveToGallery boolValue]) { - self.saveVideoToGallery = TRUE; + self.saveVideoToGallery = YES; } else { - self.saveVideoToGallery = FALSE; + self.saveVideoToGallery = NO; } } else { // set to TRUE as default - self.saveVideoToGallery = TRUE; + self.saveVideoToGallery = YES; } NSString* mediaType = nil;