2012-11-09 14 views
2

目前,我正在開發中,我已保存錄制的視頻記錄的目錄和我如何獲得NSdocument目錄保存的視頻

代碼是在這裏的應用程序:

 NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ; 

    NSData * movieData = [NSData dataWithContentsOfURL:movieURL]; 

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

    NSString *documentsDirectory = [documentPaths objectAtIndex:0]; 

    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[[self video]text]]; 

    fullPath = [fullPath stringByAppendingFormat:@".MOV"]; 

     [movieData writeToFile:fullPath atomically:YES]; 

現在我該怎麼檢查視頻是否保存在文檔目錄中?

回答

2

您可以使用此代碼獲取所有保存的視頻: -

-(IBAction)getallVideo 
{ 
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *library = [path objectAtIndex:0]; 

    NSArray *fileArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:library error:nil]; 

    videolist = [[NSMutableArray alloc]init]; 

     for(int i = 0;i<fileArray.count;i++){ 
    NSLog(@"table%d",fileArray.count); 
    id myArrayElement = [fileArray objectAtIndex:i]; 
    if([myArrayElement rangeOfString:@".mp4" ].location !=NSNotFound) 
    { 
     [videolist addObject:myArrayElement]; 

    } 
    else if([myArrayElement rangeOfString:@".mov"].location !=NSNotFound) 
    { 

    [videolist addObject:myArrayElement]; 
    } 
NSLog(@"Mu %@",videolist); 

} 
1
BOOL _isSaved = [movieData writeToFile:fullPath atomically:YES]; 

if(_isSaved == YES)} 

    NSLog(@"Saved Succesfully") 
} 
else{ 

    NSLog(@"Error occured"); 
} 

NSError* error; 
[movieData writeToFile:storePath options:NSDataWritingAtomic error:&error]; 

if(error == nil){ 

    NSLog(@"Saved Succesfully") 

} 
else{ 

     NSLog(@"write error %@", error); 
} 
+0

或BOOL成功; NSFileManager * fileManager = [NSFileManager defaultManager];成功= [fileManager fileExistsAtPath:fullPath]; if(success){NSLog(@「file already exists」);} –