Skip to content

Commit

Permalink
video picker issue fixed (#7)
Browse files Browse the repository at this point in the history
* videopicker issue fixed

* fixes
  • Loading branch information
adylevy authored Jun 7, 2018
2 parents b90ca81 + 5eefa3c commit 59f4eeb
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions ios/src/ImageCropPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ - (UIViewController*) getRootVC {
if ([[self.options objectForKey:@"useFrontCamera"] boolValue]) {
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}

if ([mediaType isEqualToString:@"video"]) {


Expand Down Expand Up @@ -222,7 +222,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
if([[self.options objectForKey:@"includeExif"] boolValue]) {
exif = [info objectForKey:UIImagePickerControllerMediaMetadata];
}

NSURL *fileURL = info[UIImagePickerControllerMediaURL];
NSString *mediaType = [self.options objectForKey:@"mediaType"];
if ([mediaType isEqualToString:@"video"]) {
Expand Down Expand Up @@ -250,8 +250,8 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
if([[self.options objectForKey:@"includeExif"] boolValue]) {
exif = [info objectForKey:UIImagePickerControllerMediaMetadata];
}
NSData* imageData = UIImageJPEGRepresentation(chosenImage, 1);
[self processSingleImagePick:imageData withExif:exif withViewController:picker withSourceURL:self.croppingFile[@"sourceURL"] withLocalIdentifier:self.croppingFile[@"localIdentifier"] withFilename:self.croppingFile[@"filename"] withCreationDate:self.croppingFile[@"creationDate"] withModificationDate:self.croppingFile[@"modificationDate"]];
NSData* imageData = UIImageJPEGRepresentation(chosenImage, 1);
[self processSingleImagePick:imageData withExif:exif withViewController:picker withSourceURL:self.croppingFile[@"sourceURL"] withLocalIdentifier:self.croppingFile[@"localIdentifier"] withFilename:self.croppingFile[@"filename"] withCreationDate:self.croppingFile[@"creationDate"] withModificationDate:self.croppingFile[@"modificationDate"]];
}

}
Expand Down Expand Up @@ -463,12 +463,10 @@ - (void)showActivityIndicator:(void (^)(UIActivityIndicatorView*, UIView*))handl
[self.loadingLabel setFont:[UIFont boldSystemFontOfSize:18]];
[loadingView addSubview:self.loadingLabel];

// PS :- Created Cancel Button
// create Cancel Button

self.btnCancel = [[UIButton alloc]initWithFrame:CGRectMake(0, loadingView.frame.size.height-50, loadingView.frame.size.width, 50)];

[self.btnCancel addTarget:self action:@selector(btnCancelAction:) forControlEvents:UIControlEventTouchUpInside];

[self.btnCancel setTitle:@"Cancel" forState:UIControlStateNormal];
[self.btnCancel setTitle:@"Cancel" forState:UIControlStateSelected];
[self.btnCancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
Expand Down Expand Up @@ -510,23 +508,15 @@ - (void) getVideoAssetFromCamera:(AVURLAsset*)avAsset fileExtension:(NSString *)
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
// save to temp directory

NSString *strFileName = [[[NSUUID UUID] UUIDString] stringByAppendingString:[NSString stringWithFormat:@".%@",fileExtension]];
NSString *filePath = [[self getTmpDirectory] stringByAppendingString:strFileName];


NSURL *outputURL = [NSURL fileURLWithPath:filePath];

exportSession.outputURL = outputURL;
NSLog(@"videopath of your file = %@",filePath); // PATH OF YOUR FILE
exportSession.outputFileType = AVFileTypeMPEG4;

[exportSession exportAsynchronouslyWithCompletionHandler:^{

if ([exportSession status] == AVAssetExportSessionStatusCompleted) {
AVAsset *compressedAsset = [AVAsset assetWithURL:outputURL];

AVAssetTrack *videoTrack = [[compressedAsset tracksWithMediaType:AVMediaTypeVideo] firstObject];
NSNumber *filesize = nil;
[outputURL getResourceValue:&filesize forKey:NSURLFileSizeKey error:nil];
Expand All @@ -545,9 +535,7 @@ - (void) getVideoAssetFromCamera:(AVURLAsset*)avAsset fileExtension:(NSString *)
withModificationDate:[NSDate date]];
completion(video);
}

}];

}
} @catch(NSException *e) {

Expand All @@ -569,20 +557,28 @@ - (void) getVideoAsset:(PHAsset*)forAsset completion:(void (^)(NSDictionary* ima
});
};


// PS :- get Video File Name with Extension and Mime Type from PHAsset Object
NSString *mimeType = @"";
NSString *filename = [forAsset valueForKey:@"filename"];
NSString *fileExtension = [filename pathExtension];
NSString *strFileName = filename;
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[filename pathExtension], NULL);
CFStringRef MIMETYPE = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);

CFRelease(UTI);
if (MIMETYPE) {
mimeType = (NSString *)CFBridgingRelease(MIMETYPE);
}

NSString *strFileName = filename;
NSString *filePath = [[self getTmpDirectory] stringByAppendingString:strFileName];
NSFileManager *fileManager = [NSFileManager defaultManager];

if ([fileManager fileExistsAtPath:filePath]){
NSError *error;
BOOL success = [fileManager removeItemAtPath:filePath error:&error];
if(!success){
strFileName = [[[NSUUID UUID] UUIDString] stringByAppendingString:[NSString stringWithFormat:@".%@",fileExtension]];
filePath = [[self getTmpDirectory] stringByAppendingString:strFileName];
}
}

NSURL *outputURL = [NSURL fileURLWithPath:filePath];
// Get compression presets
NSString *presetKey = [self.options valueForKey:@"compressVideoPreset"];
Expand Down Expand Up @@ -624,6 +620,9 @@ - (void) getVideoAsset:(PHAsset*)forAsset completion:(void (^)(NSDictionary* ima
withModificationDate:forAsset.modificationDate];
completion(video);
}
else{
completion(nil);
}
}];
}];
[self.arrImageProcessId addObject:[NSNumber numberWithInt: imageRequest]];
Expand Down Expand Up @@ -715,7 +714,7 @@ - (void)qb_imagePickerController:
didFinishPickingAssets:(NSArray *)assets {

self.manager = [PHImageManager defaultManager];

PHImageRequestOptions* options = [[PHImageRequestOptions alloc] init];
options.synchronous = NO;
options.networkAccessAllowed = YES;
Expand Down Expand Up @@ -861,9 +860,9 @@ - (void)qb_imagePickerController:
dispatch_async(dispatch_get_main_queue(), ^{
[indicatorView stopAnimating];
[overlayView removeFromSuperview];
[self.arrImageProcessId removeAllObjects];
[self.arrImageProcessId removeAllObjects];
[self processSingleImagePick:imageData

withExif: exif
withViewController:imagePickerController
withSourceURL:[sourceURL absoluteString]
Expand All @@ -890,7 +889,7 @@ - (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePicker

- (void) processSingleImagePick:(NSData*)imageData withExif:(NSDictionary*) exif withViewController:(UIViewController*)viewController withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename withCreationDate:(NSDate*)creationDate withModificationDate:(NSDate*)modificationDate {
UIImage* image = [UIImage imageWithData:imageData];

if (image == nil) {
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
self.reject(ERROR_PICKER_NO_DATA_KEY, ERROR_PICKER_NO_DATA_MSG, nil);
Expand All @@ -913,7 +912,7 @@ - (void) processSingleImagePick:(NSData*)imageData withExif:(NSDictionary*) exif
} else {

ImageResult * imageResult = getResizedCompressedImageIfNeedded(self, imageData);

NSString *filePath = [self persistFile:imageResult.data];
if (filePath == nil) {
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
Expand Down Expand Up @@ -1107,3 +1106,4 @@ + (NSDictionary *)cgRectToDictionary:(CGRect)rect {
}

@end

0 comments on commit 59f4eeb

Please sign in to comment.