IOS -how可以UISaveVideoAtPathToSavedPhotosAlbum返回保存的视频路径?

lin*_*hao 5 iphone video ios

- (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);
    } 
}
Run Code Online (Sandbox Code Playgroud)

我使用UISaveVideoAtPathToSavedPhotosAlbum来保存录制的视频.我想知道专辑中保存录制视频的绝对路径.

我怎么能得到保存的路径?UISaveVideoAtPathToSavedPhotosAlbum不返回任何内容.

并在回调函数video:didFinishSavingWithError:contextInfo:仍然没有路径信息.

Dil*_*mar 2

据我所知..您无法获取相册中保存的视频的路径。如果您希望从您的应用程序重播文件列表。您可以将所有视频放入您的应用程序中。

以下是放入 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];
Run Code Online (Sandbox Code Playgroud)

希望这对你有帮助..