【问题标题】:Storing recorded video URL for saving to library later存储录制的视频 URL 以便稍后保存到库
【发布时间】:2011-10-27 09:32:11
【问题描述】:

我有一个录制视频的应用程序。但是录制完成后,我无法立即保存视频。我需要先出示一份协议。所以我尝试保存从图像选择器获得的 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"
)

【问题讨论】:

    标签: ios5 uiimagepickercontroller


    【解决方案1】:

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

    OP 写道:

    错误的代码是:

    tempMoviePath = moviePath;
    

    因为我要设置一个已声明的属性,所以我必须使用 set & get 方法。应该是:

    [self setTempMoviePath:moviePath];
    

    显然 iOS 4 对此并不难,但 iOS5 无法处理。但是,无论如何,这样写是错误的。我承认我的错误。 :)

    【讨论】:

      猜你喜欢
      • 2018-02-10
      • 2022-10-14
      • 1970-01-01
      • 2019-09-09
      • 2010-10-25
      • 1970-01-01
      • 2016-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多