【问题标题】:Get information of the video saved to photos album by URL通过 URL 获取保存到相册的视频信息
【发布时间】:2016-06-16 09:07:09
【问题描述】:

我正在使用writeVideoAtPathToSavedPhotosAlbum 保存从AVCaptureVideoDataOutputAVAsset 获得的视频,如下所示。

    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
}

【问题讨论】:

    标签: ios objective-c avfoundation avasset


    【解决方案1】:

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

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

    希望对您有所帮助...:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-24
      • 2019-07-07
      • 1970-01-01
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多