ALAssetLibrary からビデオを取得して、それを処理できるようにしようとしています。私はそれを行うためにブロックを使用しています:
NSMutableArray *assets = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
NSLog(@"library allocated");
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
NSLog(@"Begin enmeration");
[group setAssetsFilter:[ALAssetsFilter allVideos]];
NSLog(@"Filter by videos");
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:[group numberOfAssets]-1]
options:0
usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
NSLog(@"Asset retrieved");
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
NSURL *url = [representation url];
AVAsset *recentVideo = [AVURLAsset URLAssetWithURL:url options:nil];
[assets addObject:recentVideo];
NSLog(@"Asset added to array");
}
}];
}
AVMutableComposition *composition = [[AVMutableComposition alloc] init];
NSLog(@"creating source");
AVURLAsset* sourceAsset = [assets objectAtIndex:0];
コードを実行すると、ブロックがスキップされ、配列内の要素にアクセスしようとすると、存在しないためにプログラムがクラッシュします。ブロックが非同期だからだと言われましたが、他のすべてよりも先にブロックを実行する方法がわかりません。performSelectorOnMainThread はそれができるように聞こえますが、これをどのように行うかを説明するものは実際には見つかりません。