2011-10-27 40 views
5

我有一個應用程序在錄製視頻。但是當錄製完成後,我無法立即保存視頻。我需要先表明一個協議。所以我嘗試保存從圖像選擇器獲得的URL。然後將視頻保存到圖書館。 這適用於iOS4,但不適用於iOS5。 我是iOS和Objective-C的新手,所以我可能對應該保存URL的屬性做了一些完全錯誤的聲明。存儲錄製的視頻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 

輸出記錄何時d oing「saveMyVideo」。網址突然變成了這個! :

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

回答

0

(通過在一個問題編輯OP回答見Question with no answers, but issue solved in the comments (or extended in chat)

的OP寫道:

的錯誤代碼是:

tempMoviePath = moviePath; 

因爲我設置了一個聲明的屬性,所以我必須se設置&獲取方法。它應該是:

[self setTempMoviePath:moviePath]; 

顯然的iOS 4是不是很難在這一點,但iOS5中不能處理它。但是,無論如何,這是錯誤的寫作。我承認我的錯誤。 :)