美文网首页
PHAsset 获取相册中的视频url

PHAsset 获取相册中的视频url

作者: 杨继磊 | 来源:发表于2019-04-16 12:39 被阅读0次
      PHFetchOptions *options = [[PHFetchOptions alloc] init];
        options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
        PHFetchResult *assetsFetchResults = [PHAsset fetchAssetsWithOptions:options];
        // 这时 assetsFetchResults 中包含的,应该就是各个资源(PHAsset)
        for (NSInteger i = 0; i < assetsFetchResults.count; i++) {
            // 获取一个资源(PHAsset)
            PHAsset *phAsset = assetsFetchResults[i];
            if (phAsset.mediaType == PHAssetMediaTypeVideo) {
                PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
                options.version = PHImageRequestOptionsVersionCurrent;
                options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
                
                PHImageManager *manager = [PHImageManager defaultManager];
                [manager requestAVAssetForVideo:phAsset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
                    AVURLAsset *urlAsset = (AVURLAsset *)asset;
                    
                    NSURL *url = urlAsset.URL;
                    NSData *data = [NSData dataWithContentsOfURL:url];
                    
                    NSLog(@"%@",data);
                }];
            }
        } 
    

    相关文章

      网友评论

          本文标题:PHAsset 获取相册中的视频url

          本文链接:https://www.haomeiwen.com/subject/jjxbwqtx.html