1. 程式人生 > >通過assetURL獲取到視訊

通過assetURL獲取到視訊


title: 通過assetURL獲取到視訊
date: 2017-12-14 15:02:47
tags: 原創分享

首先匯入標頭檔案

#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);
    PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
    options.version = PHImageRequestOptionsVersionCurrent;
    options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
    
    PHImageManager *manager = [PHImageManager defaultManager];
    [manager requestAVAssetForVideo:asset
                            options:options
                      resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
                          AVURLAsset *vedioUrlAsset = (AVURLAsset *)asset;
                          NSURL *vedioUrl = vedioUrlAsset.URL;
                          NSData *data = [NSData dataWithContentsOfURL:vedioUrl];
   
                      }];