- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
//get the videoURL
NSString *tempFilePath = [videoURL path];
if ( UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath))
{
// Copy it to the camera roll.
UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, @selector(video:didFinishSavingWithError:contextInfo:), tempFilePath);
}
}
我使用 UISaveVideoAtPathToSavedPhotosAlbum 来保存录制的视频。我想知道我保存录制视频的相册中的绝对路径。
如何获取保存的路径? UISaveVideoAtPathToSavedPhotosAlbum 不返回任何内容。
在回调函数video:didFinishSavingWithError:contextInfo:仍然没有路径信息。
最佳答案
据我所知.. 您无法获取保存在相册中的视频的路径。如果您希望从您的应用程序重播文件列表。您可以在应用程序中包含所有视频。
以下是您放置在 didFinishPickingMedia 中的示例代码,用于将视频存储在辅助文档中。这样您就可以跟踪它。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d", 1]];
NSString *fileName = [NSString stringWithFormat:@"%@ :%@.%@", itsIncidentType, [dateFormatter stringFromDate:incidentDate], @"mp4"];
[dateFormatter release];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder
NSURL *videoURL = [imageInfo objectForKey:UIImagePickerControllerMediaURL];
NSData *webData = [NSData dataWithContentsOfURL:videoURL];
self.itsVideoName = fileName;
[webData writeToFile:[NSString stringWithFormat:@"%@/%@",dataPath,fileName] atomically:TRUE];
希望这对你有帮助..
关于iphone - IOS - UISaveVideoAtPathToSavedPhotosAlbum 如何返回保存的视频路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10929107/