2014-04-08 62 views
0

我正在捕獲視頻剪輯,但我試圖將該文件保存到應用程序文檔目錄。我得到以下不兼容的指針類型nsurl到nsstring

不兼容的指針類型發送 'NSURL' 到類型的參數 '的NSString *'

在videoURL與NSData的線?

int timestamp = [[NSDate date] timeIntervalSince1970]; 
NSURL *videoURL = _movieURL; 
NSData *videoData = [NSData dataWithContentsOfFile: videoURL]; 

NSString *videoString = [NSString stringWithFormat:@"%d.MOV", timestamp]; 
NSString *videoPath = [documentsPath stringByAppendingPathComponent: videoString]; //Add the file name 

[videoData writeToFile:videoPath atomically:NO]; 


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 
    self.movieURL = info[UIImagePickerControllerMediaURL]; 
    // NSLOg("MOVIE URL: %@", _movieURL); 
    [picker dismissViewControllerAnimated:YES completion:NULL]; 
} 
+0

什麼是時間戳......無論是其文件位置字符串或其他? – svmrajesh

+2

[dataWithContentsOfFile:](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html#//apple_ref/occ/clm/NSData/dataWithContentsOfFile: )需要一個NSString – pNre

回答

6

videoURL是NSURL類型的

NSURL *videoURL = _movieURL; 

所以不是

NSData *videoData = [NSData dataWithContentsOfFile: videoURL]; 

嘗試下面的代碼,你有網址,而不是字符串

NSData *videoData = [NSData dataWithContentsOfURL: videoURL]; 
+0

?你剛從用戶問題中複製了一行代碼。這不能解決任何問題 –

+0

問題:獲取一個「不兼容的指針類型發送'nsurl'參數的類型'nsstring *'在videoURL與NSData線。這意味着,而不是字符串,有一個URL到那裏如果dataWithContentsOfFile被dataWithContentsOfURl取代,它可能會解決這個問題,希望能夠澄清我的答案,快樂編碼!! – Dili

0

嘗試內imagePickerController此行保存視頻

UISaveVideoAtPathToSavedPhotosAlbum (
        moviePath, nil, nil, nil); 

代碼:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info; { 
    // Handle a movie capture 
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0) 
     == kCFCompareEqualTo) { 

    NSString *moviePath = [[info objectForKey: 
       UIImagePickerControllerMediaURL] path]; 

    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) { 
     UISaveVideoAtPathToSavedPhotosAlbum (
       moviePath, nil, nil, nil); 
    } 
} 
} 
0

試試這個....使用NSMutableData,而不是NSData的

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSDate *aDate = [NSDate date]; 
NSTimeInterval interval = [aDate timeIntervalSince1970]; 
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.mov",(int)interval]]; 
[vidData writeToFile:localFilePath atomically:YES]; 
+0

在這裏簽出你可能會得到一個答案... http://stackoverflow.com/questions/6970604/how-to-capture-視頻及到保存成 - 文件 - 目錄的,iphone – Praksha

相關問題