Skip to content

Instantly share code, notes, and snippets.

@mrsidique
Created October 31, 2012 06:27
Show Gist options
  • Save mrsidique/3985425 to your computer and use it in GitHub Desktop.
Save mrsidique/3985425 to your computer and use it in GitHub Desktop.
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Within the group enumeration block, filter to enumerate just videos.
[group setAssetsFilter:[ALAssetsFilter allVideos]];
// For this example, we're only interested in the first item.
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:([group numberOfAssets]-1)]
options:0
usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
NSURL *url = [representation url];
NSLog(@"%@", url);
[_videoPlaybackView setHidden:NO];
_videoPlaybackView.hidden = NO;
[_player setContentURL:url];
[_player setControlStyle:MPMovieControlStyleEmbedded];
[_player play];
//AVAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
// Do something interesting with the AV asset.
}
}];
}
failureBlock: ^(NSError *error) {
// Typically you should handle an error more gracefully than this.
NSLog(@"No groups");
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment