Ios 从iPhone照片库中选择视频
我正在尝试使用UIImagePickerController从iPhone照片库中拾取视频,以便将其上载到服务器。 我能够使用UIImagePickerController拾取图像,没有任何错误/崩溃,但在选择(不是实际单击“选择”按钮,而是从库中选择视频)视频时,我的应用程序崩溃。 它只在控制台上打印以下行: 设置电影路径:(空) 设置电影路径:/Users/Mahesh/Library/Application Support/iPhone 模拟器/6.1/Media/DCIM/100APPLE/IMG_0006.mp4 事件在调用委托方法之前,未调用委托方法didFinishPickingMediaWithInfo。我只是无法找出问题的真正原因 以下是我打开iPhone库的代码:Ios 从iPhone照片库中选择视频,ios,iphone,objective-c,xcode5,uiimagepickercontroller,Ios,Iphone,Objective C,Xcode5,Uiimagepickercontroller,我正在尝试使用UIImagePickerController从iPhone照片库中拾取视频,以便将其上载到服务器。 我能够使用UIImagePickerController拾取图像,没有任何错误/崩溃,但在选择(不是实际单击“选择”按钮,而是从库中选择视频)视频时,我的应用程序崩溃。 它只在控制台上打印以下行: 设置电影路径:(空) 设置电影路径:/Users/Mahesh/Library/Application Support/iPhone 模拟器/6.1/Media/DCIM/100APPL
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
//imagePicker.mediaTypes = [NSArray arrayWithObjects:@"public.movie", nil];
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"];
// Compressing the image size
CGSize newSize = CGSizeMake(400, 400);
UIGraphicsBeginImageContext(newSize);
[editedImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
// Get the new image from the context
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// End the context
UIGraphicsEndImageContext();
NSData *data = UIImageJPEGRepresentation(newImage,0.2);//PNGRepresentation(imgView.image);
}
else if ([mediaType isEqualToString:@"public.movie"]){
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
请帮帮我。。谢谢 一切看起来都很好 您是否在头文件中设置了委托 我只能建议两件事:
[mediaType isEqualToString:@"public.image"]
与
并将视频留给else语句
您需要为该检查导入
。
希望这有帮助
编辑:您还可以尝试添加imagePicker.allowsdediting=NO代码>试试看
picker.mediaTypes = @[(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage];
我已经在头文件中设置了代理。我也导入了,但问题仍然存在:(我在iOS 6.1上遇到了同样的问题,但代码在iOS 7上仍然运行良好。您使用的是siulator还是实际设备?我认为您的代码在设备上可以运行,但在模拟器上会崩溃。
picker.mediaTypes = @[(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage];