Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ios/CDVCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum CDVCaptureError {
CAPTURE_PERMISSION_DENIED = 4,
CAPTURE_NOT_SUPPORTED = 20
};

typedef NSUInteger CDVCaptureError;

@interface CDVImagePicker : UIImagePickerController
Expand All @@ -49,8 +50,10 @@ 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;
Expand Down Expand Up @@ -117,3 +120,5 @@ typedef NSUInteger CDVCaptureError;
- (NSString*)formatTime:(int)interval;
- (void)updateTime;
@end


42 changes: 34 additions & 8 deletions src/ios/CDVCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ - (void)viewWillAppear:(BOOL)animated {

@implementation CDVCapture
@synthesize inUse;

@synthesize saveVideoToGallery;
- (void)pluginInitialize
{
self.inUse = NO;
self.saveVideoToGallery = NO;
}

- (void)captureAudio:(CDVInvokedUrlCommand*)command
Expand Down Expand Up @@ -213,6 +214,7 @@ - (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCal

- (void)captureVideo:(CDVInvokedUrlCommand*)command
{

NSString* callbackId = command.callbackId;
NSDictionary* options = [command argumentAtIndex:0];

Expand All @@ -224,6 +226,23 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command
// 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(![[options allKeys] containsObject: @"frontFacing"]) {
// set to TRUE as default
frontFacing = [NSNumber numberWithInt: 1];
}
if([[options allKeys] containsObject: @"saveToGallery"]) {
if ([saveToGallery boolValue]) {
self.saveVideoToGallery = YES;
} else {
self.saveVideoToGallery = NO;
}
} else {
// set to TRUE as default
self.saveVideoToGallery = YES;
}

NSString* mediaType = nil;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
Expand Down Expand Up @@ -282,6 +301,11 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command
// pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
// pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
}
if ([frontFacing boolValue]) {
pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
} else {
pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
}
// CDVImagePicker specific property
pickerController.callbackId = callbackId;
pickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
Expand All @@ -293,13 +317,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];
Expand Down
4 changes: 4 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down