1

我正在使用 requestExportSessionForVideo 方法从 PHAsset 获取可发送视频,但我收到此警告,并且导出会话记录了一个空值:

Null passed to a callee that requires a non-null argument

这是方法调用:

[manager requestExportSessionForVideo:asset options:videoOptions exportPreset:AVAssetExportSessionStatusUnknown resultHandler:^(AVAssetExportSession * _Nullable exportSession, NSDictionary * _Nullable info) {
            NSLog(@"Export session is: %@ ///// Info is %@", exportSession, info);
        }];

但是,打印的信息看起来不错:

Info is {
PHImageFileSandboxExtensionTokenKey = "8b504346993c71de48743d3c9c796385d7911ad2;00000000;00000000;000000000000001b;com.apple.avasset.read-only;00000001;01000002;00000000000468eb;/private/var/mobile/Media/DCIM/100APPLE/IMG_0004.MOV";
PHImageResultDeliveredImageFormatKey = 20000;
PHImageResultIsInCloudKey = 0;
PHImageResultWantedImageFormatKey = 20000;
}

如何从 PHAsset 中获取可以发送到云容器的视频对象?这个警告会影响输出吗?请注意,我的资产是使用 GMImagePicker 选择的。

4

3 回答 3

3

Swift - 在这里,使用 requestAVAssetForVideo 获取视频 url 的解决方案......它对我有用......

let options = PHVideoRequestOptions()
options.version = .Original
options.deliveryMode = .Automatic
options.networkAccessAllowed = true

PHCachingImageManager.defaultManager().requestAVAssetForVideo(asset, options: options, resultHandler:
                                {
                                    (avAsset, audioMix, info) in

                                    dispatch_sync(dispatch_get_main_queue(),{
                                        let theAsset = avAsset as! AVURLAsset
                                        let videoURL = theAsset.URL
                                        print(videoURL)

                                    })
                            })
于 2016-05-09T09:23:07.867 回答
3

这可能会帮助您进一步进行。我目前面临同样的问题。但以下方法给了我视频网址。

PHVideoRequestOptions* options = [[PHVideoRequestOptions alloc] init];
    options.version = PHVideoRequestOptionsVersionOriginal;
    options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
    options.networkAccessAllowed = YES;
    options.progressHandler =  ^(double progress,NSError *error,BOOL* stop, NSDictionary* dict) {
        NSLog(@"progress %lf",progress);  //never gets called
    };


[[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset* avasset, AVAudioMix* audioMix, NSDictionary* info){
        NSLog(@"##Info:\n%@",info);
        AVURLAsset* myAsset = (AVURLAsset*)avasset;
        NSLog(@"##AVAsset URL: %@",myAsset.URL);
    }];


输出

2015-11-25 12:00:04.482 iLockBox[7602:2587808] ##Info:
{
    PHImageFileSandboxExtensionTokenKey = "7c2094f4c69015b87df6d7c86ec3217cc544e2e2;00000000;00000000;000000000000001b;com.apple.avasset.read-only;00000001;01000002;0000000000ff9a15;/private/var/mobile/Media/DCIM/111APPLE/IMG_1087.MOV";
    PHImageResultDeliveredImageFormatKey = 20000;
    PHImageResultIsInCloudKey = 0;
    PHImageResultWantedImageFormatKey = 20000;
}
2015-11-25 12:00:16.007 iLockBox[7602:2587808] ##AVAsset URL: file:///var/mobile/Media/DCIM/111APPLE/IMG_1087.MOV



请评论您的结果。

于 2015-11-25T06:37:48.887 回答
1

为方便起见,@Pankaj 工作答案的 Swift 3 版本

let options = PHVideoRequestOptions()
options.version = .original
options.deliveryMode = .automatic
options.isNetworkAccessAllowed = true

PHCachingImageManager.default().requestAVAsset(forVideo: phAsset, options: options, resultHandler:{ (avAsset, audioMix, info) in

       DispatchQueue.main.async {
          let theAsset = avAsset as! AVURLAsset
          let videoURL = theAsset.url
          print(videoURL)
       }
})
于 2017-06-16T12:58:27.617 回答