保存后获取视频文件名

时间:2014-02-11 18:40:30

标签: ios uiimagepickercontroller

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

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

我已经可以得到这个......

/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);
        }


    }
}

1 个答案:

答案 0 :(得分:0)

包括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);
}];