如何获取NSdocument目录保存的视频

时间:2012-11-09 09:42:49

标签: iphone xcode ios6

目前,我正在开发一个应用程序,我已将录制的视频保存到文档目录和我的

代码在这里:

     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 个答案:

答案 0 :(得分: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 :(得分: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);
 }