Currently, I am developing an app in which I have saved recorded video to document directory and my
code is here:
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];
Now how can I check that videos are save in document directory or not?
you can get all saved video using this code:-
-(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);
}
BOOL _isSaved = [movieData writeToFile:fullPath atomically:YES];
if(_isSaved == YES)}
NSLog(@"Saved Succesfully")
}
else{
NSLog(@"Error occured");
}
or
NSError* error;
[movieData writeToFile:storePath options:NSDataWritingAtomic error:&error];
if(error == nil){
NSLog(@"Saved Succesfully")
}
else{
NSLog(@"write error %@", error);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.