2

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

代码在这里:

     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];

现在如何检查视频是否保存在文档目录中?

4

2 回答 2

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);

}
于 2012-11-09T09:46:37.033 回答
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);
 }
于 2012-11-09T09:46:32.247 回答