Upload videos from gallery using Photos framework

有些话、适合烂在心里 提交于 2019-12-03 01:20:23

Seems the only valid way is to request AVAsset from PHImageManager, and check if returned asset is AVURLAsset. In this case URL can be used to directly access file and get needed chunk of bytes:

[[PHImageManager defaultManager] requestAVAssetForVideo:videoAsset options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
  if ([asset isKindOfClass:[AVURLAsset class]]) {
    NSURL *URL = [(AVURLAsset *)asset URL];
    // use URL to get file content
  }
}];

This will not work with slow motion videos, because AVComposition instead of AVURLAsset is returned. Possible solution is to use PHVideoRequestOptionsVersionOriginal video file version:

PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.version = PHVideoRequestOptionsVersionOriginal;

[[PHImageManager defaultManager] requestAVAssetForVideo:videoAsset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
  if ([asset isKindOfClass:[AVURLAsset class]]) {
    NSURL *URL = [(AVURLAsset *)asset URL];
    // use URL to get file content
  }
}];

And to get fullsize image url:

PHContentEditingInputRequestOptions *options = [[PHContentEditingInputRequestOptions alloc] init];
options.canHandleAdjustmentData = ^BOOL(PHAdjustmentData *adjustmentData) {
  return YES;
};

[imageAsset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
  // use contentEditingInput.fullSizeImageURL
}];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!