【问题标题】:Get video file name after saving保存后获取视频文件名
【发布时间】:2014-02-12 04:36:26
【问题描述】:

我使用下面的代码来保存视频,它工作正常。视频保存在设备上。

我确实需要保存的文件的名称。

我已经可以得到这个了……

/private/var/mobile/Applications/D495AC17-F672-4D61-BBEB-7AC92358E0FF/tmp/capture-T0x16e2c250.tmp.cknraL/capturedvideo.MOV

但我需要保存名称。

任何帮助将不胜感激。

谢谢

- (void) imagePickerController: (UIImagePickerController *) picker
 didFinishPickingMediaWithInfo: (NSDictionary *) info {

    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];

    [self dismissModalViewControllerAnimated:NO];

    // Handle a movie capture
    if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
    {

        NSString *moviePath = [[info objectForKey:
                                UIImagePickerControllerMediaURL] path];


        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
        {
            UISaveVideoAtPathToSavedPhotosAlbum (moviePath,self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
        }


    }
}

【问题讨论】:

  • 来自@Elkucho:对已删除答案的评论:contextInfo 为 NULL,videoPath 的路径相同。

标签: ios uiimagepickercontroller


【解决方案1】:

包括AssetsLibrary.framework#import <AssetsLibrary/AssetsLibrary.h>

在您的 imagePickerController:didFinishPickingMediaWithInfo: 方法中,您可以执行以下操作:

NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];

ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
[assetsLibrary assetForURL:imageURL resultBlock:^(ALAsset *asset) {
    ALAssetRepresentation *assetRep = [asset defaultRepresentation];
    NSLog(@"Image filename: %@", [assetRep filename]);
} failureBlock:^(NSError *error) {
    NSLog(@"Error: %@", error.localizedDescription);
}];

【讨论】:

  • 嗯...你能把NSLog(@"%@", imageURL);的输出贴出来
  • 您能否提供新的解决方案,因为 AssetsLibrary.framework 现在已弃用
猜你喜欢
  • 1970-01-01
  • 2014-02-02
  • 2018-08-12
  • 2016-02-05
  • 1970-01-01
  • 2018-11-11
  • 2012-11-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多