I'm using an imagePickerController to record video. In the imagePickerController:didFinishPickingMediaWithInfo:
function I'm trying to set the video to a previously defined MPMoviePlayerController:
if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]){
NSURL *movieUrl = [info objectForKey:UIImagePickerControllerMediaURL];
[self.moviePlayer setContentURL:movieUrl]];
}
This is working fine and the video is indeed playing. But I want to save the file for later use. When I do this and use the saved file for the moviePlayer, nothing happens:
I've tried this (saving the data to a new file)
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *newPath = [directory stringByAppendingPathComponent:@"myMovie.mov"]; NSData *videoData = [NSData dataWithContentsOfURL:movieUrl]; [videoData writeToFile:newPath atomically:NO]; [self.moviePlayer setContentURL:[NSURL URLWithString:newPath]];
or this (copying the temp video file to my document folder)
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *newPath = [directory stringByAppendingPathComponent:@"myMovie.mov"]; NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error = nil; [fileManager copyItemAtPath:[videoUrl path] toPath:newPath error:&error]; [self.moviePlayer setContentURL:[NSURL URLWithString:newPath]];
Without any success, even though the file at newPath
does exist... What am I doing wrong?