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 是訪問照相機下的 照片 與 視頻 一個實例,簡單理解:提供訪問相冊的能力;使用以前要先進行受權詢問>app

//建立訪問相冊的實體.
    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);
    }];
相關文章
相關標籤/搜索