×

iOS 通过assetURL获取到视频

96
叫我龙哥
2017.12.14 15:16* 字数 29

首先导入头文件

#import <Photos/Photos.h>

iOS中assetURL样式:

assets-library://asset/asset.mov?id=F2E6E143-4343-4B57-87F9-346936E0EDB3&ext=mov

使用当前的URL过滤到我们想要的数据

 PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[assetUrl] options:nil];

    PHAsset * PHAsset = result.firstObject;


    /// 包含该视频的基础信息
    PHAssetResource * resource = [[PHAssetResource assetResourcesForAsset: PHAsset] firstObject];

    NSLog(@"%@",resource);
    /*
     type:
     originalFilename:
     */

    PHImageRequestOptions * options = [[PHImageRequestOptions alloc] init];

    options.version = PHImageRequestOptionsVersionCurrent;

    options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;

    options.synchronous = YES;

    __block NSData *videoData = nil;

    [[PHImageManager defaultManager] requestImageDataForAsset: PHAsset
                                                      options: options
                                                resultHandler: ^(NSData * imageData, NSString * dataUTI, UIImageOrientation orientation, NSDictionary * info) {
                                                    NSLog(@"%@",imageData);
                                                        //这里的imageData就是视频数据;
    }];


日记本
Web note ad 1