I am trying to select a video from the iPhone photo library using UIImagePickerController so that I can upload it to the server. I can select images using the UIImagePickerController without any errors / crashes, but, choosing (not pressing the select button, but just selecting a video from the library), my application crashes. It simply prints the following lines on the console:
setting the path to the movie: (null)
setting the path to the movie: / Users / Mahesh / Library / Application Support / iPhone Simulator / 6.1 / Media / DCIM / 100APPLE / IMG_0006.mp4
Event: the didFinishPickingMediaWithInfo delegate method is not called before the application crashes. I just can't figure out what actually causes the problem.
Below is my code to open the iPhone library:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
[self presentViewController:imagePicker animated:YES completion:nil];
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]){
UIImage *editedImage = (UIImage *)[info objectForKey:@"UIImagePickerControllerOriginalImage"];
CGSize newSize = CGSizeMake(400, 400);
UIGraphicsBeginImageContext(newSize);
[editedImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data = UIImageJPEGRepresentation(newImage,0.2);
}
else if ([mediaType isEqualToString:@"public.movie"]){
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
Please help me .. Thank you!
source
share