Saving / extracting video files in iOS

I looked through, but could not find a solution to my problem. I am trying to save some video files in my application directory. I do it as follows:

  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

// the path to write file
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"myFile"];
NSLog(@"%@",appFile);

[[NSUserDefaults standardUserDefaults] setValue:appFile forKey:@"videoURL"];
[[NSUserDefaults standardUserDefaults]synchronize];
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *webData = [NSData dataWithContentsOfURL:videoURL];
[webData writeToFile:appFile atomically:YES];

My question is, is this the right way to save a movie file, and if so, how can I convert NSData to a file that can be played through MPMoviePlayer? Thank you for your help.

PS. I really do not want to use the photo library, since the application is likely to contain a lot of videos.

+3
source share
1 answer

If you really want to save it in the documents of your application, you will have to use NSFileManager

it will probably look something like this.

NSString* completeFileName = [NSString stringWithFormat:@"%@",movieName];
NSString* filename = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:completeFileName];

[[NSFileManager defaultManager] createFileAtPath:filename contents:yourMovieData attributes:nil];

NSFileHandle

MPMoviePlayer, , NSURL,

[NSURL fileURLWithPath:path isDirectory:NO];

URL- MPMoviePlayer.

, .

+4

All Articles