通过URL获取保存到相册的视频信息

时间:2016-06-16 09:07:10

标签: ios objective-c avfoundation avasset

我使用AVCaptureVideoDataOutput保存从AVAsset writeVideoAtPathToSavedPhotosAlbum获得的视频,如下所示。

    NSString* filename = [NSString stringWithFormat:@"capture%d.mp4", _currentFile];
    NSString* path = [NSTemporaryDirectory() stringByAppendingPathComponent:filename];
    NSURL* url = [NSURL fileURLWithPath:path];

    dispatch_async(dispatch_get_main_queue(), ^{
        [_encoder finishWithCompletionHandler:^{
            ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
            [library writeVideoAtPathToSavedPhotosAlbum:url completionBlock:^(NSURL *assetURL, NSError *error){
                NSLog(@"save completed");
            }];
        }];
    });

但是在保存视频后,我想要获取已保存的视频信息'回到过去,就像我们在使用UIImagePickerController时得到的一样。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:NULL];

    NSLog(@"there");

    // Handle a movie capture
    NSString *type = info[UIImagePickerControllerMediaType];
    NSURL *videoURL = info[UIImagePickerControllerMediaURL];

    //do things with that info
}

1 个答案:

答案 0 :(得分:0)

以下是保存视频并在自定义相册中添加该视频的代码,然后告知其保存位置。

 [library writeVideoAtPathToSavedPhotosAlbum:videoInputUrl completionBlock:^(NSURL *assetURL, NSError *error){
    if (error) {

        NSLog(@"Video could not be saved");
    }
    else{

            [library assetForURL:assetURL
                     resultBlock:^(ALAsset *asset) {
                         // assign the photo to the album
                         [groupToAddTo addAsset:asset];
                         NSLog(@"Added Successfully %@ to %@", [[asset defaultRepresentation] filename], albumName);
                         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Video Saved to xyz Album."  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil, nil];
                         [alert show];
                     }
                    failureBlock:^(NSError* error) {
                        NSLog(@"failed to retrieve image asset:\nError: %@ ", [error localizedDescription]);
                    }];
    }
}];

希望这能帮助你...... :)