存储录制的视频URL以便稍后保存到库

时间:2011-10-27 09:32:11

标签: ios5 uiimagepickercontroller

我有一个录制视频的应用程序。但录制完成后,我无法立即保存视频。我需要先达成协议。所以我尝试保存从图像选择器获得的URL。稍后将视频保存到库中。 这在iOS4中运行良好,但在iOS5中运行不正常。 我是iOS和Objective-C的新手,所以我可能做了一些完全错误的属性声明,该属性应该保存URL。

这是一些代码:

·H

#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>


@interface Video_recViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate> {

NSURL *tempMoviePath;

}


@property (nonatomic, retain) NSURL *tempMoviePath;

的.m

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

NSURL *moviePath = [info objectForKey:UIImagePickerControllerMediaURL]; 
[self dismissModalViewControllerAnimated: YES];
NSLog(@"path from image picker: %@", moviePath);
tempMoviePath = moviePath;
NSLog(@"temp movie path: %@", tempMoviePath);
//
[self performSelector:@selector(showAgree) withObject:nil afterDelay:0.5];

}

- (void)userAgreed {
NSLog(@"user agreed");
//NSLog(@"temp movie path: %@", tempMoviePath);
[self saveMyVideo:tempMoviePath];
//[self performSelector:@selector(showSurvey) withObject:nil afterDelay:0.5];
}

- (void)saveMyVideo:(NSURL *)videoURL {

NSLog(@"saving movie at: %@", videoURL);

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:videoURL])
{
    [library writeVideoAtPathToSavedPhotosAlbum:videoURL
                                completionBlock:^(NSURL *assetURL, NSError *error){}
     ];
} 
[library release]; 

}

当didFinishPickingMediaWithInfo为:

时从日志输出
temp movie path: file://localhost/private/var/mobile/Applications/8CFD1CB7-70A0-465C-B730-817ACE5A4F78/tmp/capture-T0x119660.tmp.hNFzkY/capturedvideo.MOV

执行“saveMyVideo”时日志的输出。网址突然变成了!! :

saving movie at: (
"0.31269",
"0.32899",
"0.63999",
"0.33001",
"0.3",
"0.6",
"0.15",
"0.05999"
)

1 个答案:

答案 0 :(得分:0)

(OP在问题编辑中回答。见Question with no answers, but issue solved in the comments (or extended in chat)

OP写道:

  

错误的代码是:

tempMoviePath = moviePath;
  

因为我正在设置声明的属性,所以我必须使用set&amp;得到方法。它应该是:

[self setTempMoviePath:moviePath];
  

显然iOS 4并没有那么难,但iOS5无法处理它。但是,无论如何,这样的写作是错误的。我承认我的错误。 :)