在iPhone的库中保存录制的视频时出现问题 [英] Problem saving recorded video on iPhone's library
问题描述
我正在尝试使用UIImagePickerController委托将录制的视频保存到库中。它适用于图片,但如果它是一个视频则无法保存,如果我打开照片应用程序后尝试保存视频,我会收到一条消息请等待.Update字符串库,以及带有标签的进度条重建图书馆。我的照片库已恢复,但视频未添加到其中。
I am trying to save a recorded video to the library using the UIImagePickerController delegate. It works fine for pictures but it doesn't save if it's a video, plus after trying to save a video if I open the Photos app, I get a message "Please wait. Updatring library", and a progress bar with the label "Rebuilding library". My photo library is restored but the video was not added to it.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]){
UIImage *picture = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(picture, nil, nil, nil);
}
else if ([mediaType isEqualToString:@"public.movie"]){
NSString* m_objMediaURL= [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"URL is %@", m_objMediaURL);
UISaveVideoAtPathToSavedPhotosAlbum(m_objMediaURL, nil, nil, nil);
}
[self dismissModalViewControllerAnimated:YES];
}
上面的NSLog输出如下:
The NSLog above outputs the following:
URL is
file://localhost/private/var/mobile/Applications/3800A5FB-2A96-4A7A-85DF-B635E8D9A66C/tmp/capture-T0x1061f0.tmp.JMdxHq/capturedvideo.MOV
有没有人实现过这样的方法,可以指点我请问正确的方向?
Has anyone implemented such method and can point me to the right direction please?
谢谢。
推荐答案
我我想我发现了一个问题。
I think I see an issue.
NSString * m_objMediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
类型错误。我正常工作的代码使用:
Is the wrong type. My properly working code uses:
NSURL * url = [[[info objectForKey:UIImagePickerControllerMediaURL] copy] autorelease];
我复制它而不是保留它,因为在拾取器视图被解除后我在低内存情况下遇到了一些问题。虽然您使用的保存方法可能有效,但我使用的是更新更好(因为回调块):
I copy it instead of retaining it because of some issues I have had in low memory situations after the picker view is dismissed. Although the save method you use might work, I use the newer and better (because of the callback block):
ALAssetsLibrary* library = [[[ALAssetsLibrary alloc] init] autorelease];
[library writeVideoAtPathToSavedPhotosAlbum:url
completionBlock:^(NSURL *assetURL, NSError *error){/*notify of completion*/}];
此外,你应该使用 kUTTypeMovie
和 kUTTypeImage
而不是硬编码 @public.image
。
Also, you should be using kUTTypeMovie
and kUTTypeImage
instead of hard coding @"public.image
.
这篇关于在iPhone的库中保存录制的视频时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!