2016-09-28 33 views
-1

我有一個大問題,我的情況PHImageManager.default()。requestAVAsset視頻

我的主要問題是,我需要一個獲取視頻一個做視頻名稱一些操作,並將其保存到文件系統和再次獲取另一個視頻對視頻名稱進行一些操作並通過資產循環將其保存到文件系統問題是完成處理程序阻止我這樣做,因爲它將所有視頻保存在一起,而不進行任何編輯並更改名稱this save all視頻,我認爲它正在後臺線程請任何幫助解決這個問題,我需要處理獲取視頻一個接一個

這是我的代碼

for asset in arrayOfAssets { 
     if asset.mediaType == .video { 


       PHImageManager.default().requestAVAsset(forVideo: asset, options: nil, resultHandler: { (AVAsset, AVAudio, info) in 
        // i need access to this place so i can fetch the video one by one and working with the AVAsset 

       }) 


     }else{ 
      let imageOp = PHImageRequestOptions() 

      PHImageManager.default().requestImage(for: asset, targetSize: CGSize(width:125,height:125), contentMode: .aspectFit, options: imageOp, resultHandler: { (img, info) in 
       print(img!) 
      }) 

     } 

    } 

回答

-1

我認爲這一條涉及您的查詢 爲Vedios How Can i Get the List of all Video files from Library in ios sdk

的圖像 Get all of the pictures from an iPhone photoLibrary in an array using AssetsLibrary framework?

allVideos = [[NSMutableArray alloc] init]; 
 
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init]; 
 

 
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) 
 
{ 
 
    if (group) 
 
    { 
 
     [group setAssetsFilter:[ALAssetsFilter allVideos]]; 
 
     [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) 
 
      { 
 
       if (asset) 
 
       { 
 
        dic = [[NSMutableDictionary alloc] init]; 
 
        ALAssetRepresentation *defaultRepresentation = [asset defaultRepresentation]; 
 
        NSString *uti = [defaultRepresentation UTI]; 
 
        NSURL *videoURL = [[asset valueForProperty:ALAssetPropertyURLs] valueForKey:uti]; 
 
        NSString *title = [NSString stringWithFormat:@"video %d", arc4random()%100]; 
 
        UIImage *image = [self imageFromVideoURL:videoURL]; 
 
        [dic setValue:image forKey:@"image"]; 
 
        [dic setValue:title forKey:@"name"]; 
 
        [dic setValue:videoURL forKey:@"url"]; 
 
        [`allVideos` addObject:dic]; 
 
       } 
 
      }]; 
 
    else 
 
    { 
 
    } 
 
} 
 
    failureBlock:^(NSError *error) 
 
{ 
 
    NSLog(@"error enumerating AssetLibrary groups %@\n", error); 
 
}]; 
 

 
--------for ALL PHOTOS 
 
NSArray *imageArray; 
 
NSMutableArray *mutableArray; 
 

 
-(void)getAllPhotosFromCamera 
 
{ 
 
    imageArray=[[NSArray alloc] init]; 
 
    mutableArray =[[NSMutableArray alloc]init]; 
 

 
    PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init]; 
 
    requestOptions.resizeMode = PHImageRequestOptionsResizeModeExact; 
 
    requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; 
 
    requestOptions.synchronous = true; 
 
    PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil]; 
 

 
    NSLog(@"%d",(int)result.count); 
 

 
    PHImageManager *manager = [PHImageManager defaultManager]; 
 
    NSMutableArray *images = [NSMutableArray arrayWithCapacity:[result count]]; 
 

 
    // assets contains PHAsset objects. 
 

 
    __block UIImage *ima; 
 
    for (PHAsset *asset in result) { 
 
     // Do something with the asset 
 

 
     [manager requestImageForAsset:asset 
 
          targetSize:PHImageManagerMaximumSize 
 
          contentMode:PHImageContentModeDefault 
 
           options:requestOptions 
 
         resultHandler:^void(UIImage *image, NSDictionary *info) { 
 
          ima = image; 
 

 
          [images addObject:ima]; 
 
         }]; 
 

 

 
    } 
 

 
    imageArray = [images copy]; // You can direct use NSMutuable Array images 
 
}

+0

這個問題被標記爲 「雨燕」,而不是「 objective-c「... – Moritz

+0

是的埃裏克,但我們可以從這個想法。 和代碼可以轉換爲swift。 https://objectivec2swift.com/ – Rivendell

+0

但我不需要獲取所有視頻我需要訪問結果處理程序 – Mustafa