[英]Pick a video from iPhone photo library
我正在嘗試使用UIImagePickerController從iPhone照片庫中選擇一個視頻,以便我可以將其上傳到服務器。 我能夠使用UIImagePickerController選擇圖像而沒有任何錯誤/崩潰,但在選擇時(不是實際點擊選擇按鈕,而只是從庫中選擇視頻)視頻我的應用程序崩潰。 它只是在控制台上打印以下行:
設置電影路徑:(null)
設置電影路徑:/ Users / Mahesh / Library / Application Support / iPhone Simulator / 6.1 / Media / DCIM / 100APPLE / IMG_0006.mp4
事件委托方法didFinishPickingMediaWithInfo沒有被調用,在它被調用之前我的應用程序崩潰了。 我只是無法弄清楚實際導致問題的原因。
以下是我打開iPhone庫的代碼:
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];
}
請幫幫我..謝謝!
嘗試
picker.mediaTypes = @[(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage];
一切都很好看。
你是否在頭文件中設置了委托?
我只能建議兩件事:
2.當您檢查它是圖像還是視頻時,請更換
[mediaType isEqualToString:@"public.image"]
同
[mediaType isEqualToString:(NSString *)kUTTypeImage]
並留下視頻為else聲明。
您需要導入<MobileCoreServices/UTCoreTypes.h>
進行此檢查。 希望這可以幫助。
編輯 :您還可以嘗試添加imagePicker.allowsEditing = NO;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.