1

在 iOS8 之前,我使用 ALAsset 并使用缓冲区获取 NSData 然后上传视频,如下所示;

Byte * buffer = (Byte *)malloc(lenght);

NSError * error = nil;

NSUInteger readLength = [self.asset.defaultRepresentation getBytes:buffer fromOffset:self.sendedSize length:lenght error:&error];

NSData * data = [NSData dataWithBytes:buffer length:readLength];

那么,如何使用 PhotoKit 上传视频?如何获取视频数据?

4

1 回答 1

3

这个怎么样:

    PHAsset *videoAsset /*Your video asset */;
    PHVideoRequestOptions *options = /*Options if you need them */;
    [[PHImageManager defaultManager] requestAVAssetForVideo:videoAsset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
        NSURL *fileURL = /*Create a temporary file URL*/;
        exportSession.outputURL = fileURL;

        [exportSession exportAsynchronouslyWithCompletionHandler:^{
            NSData *assetData = [NSData dataWithContentsOfURL:fileURL];
            /* Do whatever you want to do with this data, and delete it afterwards */      
        }];
    }];
于 2015-11-03T21:41:33.357 回答