iphone - IOS - UISaveVideoAtPathToSavedPhotosAlbum 如何返回保存的视频路径?

标签 iphone ios video

- (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/

相关文章:

iphone - UIViewController 多个 UIView

android - Android QMediaPlayer 可以播放哪些视频文件?

ios - 在 AVFoundation AVSampleBufferDisplayLayer 中循环播放视频

iphone - 当应用程序转到后台时,我的 View Controller 被释放

iphone - CATiledLayer 和 UIScrollView,缓存一些缩放级别的旧数据

ios - 从 Xcode 项目运行应用程序时 Cocoapods 链接器错误

ios - 我可以在 Realm for Swift 中将 RealmObject 序列化为 JSON 或 NSDictionary 吗?

ios - UIButton 触摸未注册

reactjs - 有没有办法限制您的输入元素仅接受视频?

iphone - 通过 USB 从 MAC 捕获 iPhone 屏幕,无需越狱