我正在使用UIImagePicker录制视频,然后尝试将其保存到NSData格式的文档目录中。
这部分有效,但后来我无法播放?你如何让MediaPlayer播放NSData对象?
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:NULL];
self.videoURL = info[UIImagePickerControllerMediaURL];
NSLog(@"video url-%@",self.videoURL);
NSData *videoData = [NSData dataWithContentsOfURL:self.videoURL];
NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [documentDirectories firstObject];
NSString *videoPath = [documentDirectory stringByAppendingPathComponent:self.video.fileKey];
NSLog(@"video path-%@",videoPath);
[videoData writeToFile:videoPath atomically:YES];
self.videoURL = [NSURL fileURLWithPath:videoPath];
[self.videoController setContentURL:self.videoURL];
[self.videoController play];
}
答案 0 :(得分:0)
好的我解决了。在命名新路径时未添加.mov文件扩展名。