在我的APP中使用UISaveVideoAtPathToSavedPhotosAlbum将视频保存到photolibrary。我正在获取视频的路径,但我无法播放此视频。任何1可以帮助我解决如何检索已保存的视频。谢谢。我使用下面的代码。
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
} else {
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
NSLog(@"temp path %@",tempFilePath);
[picker dismissModalViewControllerAnimated:YES];
}
答案 0 :(得分:1)
此函数返回的路径需要后缀。试试这个
NSString *videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSURL *videoURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://localhost%@", videoPath]];
答案 1 :(得分:1)
NSURL * url = [NSURL fileURLWithPath:tempFilePath]; 并使用以下方式播放网址:“MPMoviePlayerController”