2015-01-31 74 views
1

我使用UIImagePicker錄製視頻,然後嘗試將其保存到NSData格式的文檔目錄中。從文檔目錄中的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

即使將視頻複製到文檔而不將其轉換爲NSData,該文件仍然會在文檔文件中作爲NSdata對象一次結束? – fiixed 2015-01-31 21:40:11

回答

0

它確定我解決了它。命名新路徑時未添加.mov文件擴展名。