AVFoundation 零碎知识

1 ALAssetsLibrary( iOS4.0-iOS9.0苹果已经废弃的框架 )
1.1 An instance of ALAssetsLibrary provides access to the videos and photos that are under the control of the Photos application. <ALAssetsLibrary 是访问照相机下的 照片 与 视频 一个实例,简单理解:提供访问相册的能力;使用之前要先进行授权询问>

    //创建访问相册的实体.
    ALAssetsLibrary*   library = [[ALAssetsLibrary alloc]init];
    
    ALAssetsGroupType:枚举值.
    
    ALAssetsGroupLibrary    // The Library group that includes all assets.
    ALAssetsGroupAlbum      // All the albums synced from iTunes or created on the device.
    ALAssetsGroupEvent      // All the events synced from iTunes.
    ALAssetsGroupFaces      // All the faces albums synced from iTunes.
    ALAssetsGroupSavedPhotos   // The Saved Photos album.

    ALAssetsGroupPhotoStream   // The PhotoStream album(照片流).
    ALAssetsGroupAll       //ALAssetsGroupAll
    //遍历所筛选的内容.
    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
        
        //group类型包括:相机胶卷(Camera Roll),我的照片流  等等
        //group 有可能为nil 
        
        if (group) {
    
            //ALAssetsGroup:组的概念相当于一个  我的照片流
            NSLog(@"this is  albumAssetGroup:%@",[group valueForProperty:ALAssetsGroupPropertyURL]);
            NSLog(@"this is  albumAssetGroup:%@",[group valueForProperty:ALAssetsGroupPropertyName]);
            NSLog(@"this is  albumAssetGroup:%@",[group valueForProperty:ALAssetsGroupPropertyType]);
  
            self.customImageView.image  = [UIImage imageWithCGImage:[group posterImage]];
            //*stop = YES;
            
        }
        
        //使用过滤器
        //Only one filter is active at a time. Any enumeration currently in flight continues to completion using the previous filter.
        [group setAssetsFilter:[ALAssetsFilter  allVideos]];
        
        if ([group numberOfAssets] <= 0 ){
            
            return ;
        }
        
        //这个方法使用的时候有可能会崩溃,前面添加numberOfAssets 进行资源数量的限定
        [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0]  options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
            
            //result:表示一个具体的资源 An ALAsset object represents a photo or a video managed by the Photo application.;
            
            if (result) {
                
                id  representation = [result defaultRepresentation];
                
                NSURL * url = [representation url];
                
                AVAsset* asset= [AVAsset assetWithURL:url];
                
                //NSLog(@"this is this is a asset url :%@",url);
                
            }

        }];
    
     
    } failureBlock:^(NSError *error) {
        
        NSLog(@"error:%@",error.localizedDescription);
    }];
    原文作者:Stephanie
    原文地址: https://segmentfault.com/a/1190000009980331
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞