Last active
December 21, 2015 04:28
-
-
Save ulrikdamm/6249271 to your computer and use it in GitHub Desktop.
Getting artwork for a audio file in Objective-C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSURL *url = [NSURL URLWithString:songFileLocation]; | |
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; | |
[asset loadValuesAsynchronouslyForKeys:@[ @"commonMetadata" ] completionHandler:^{ | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
NSArray *artwork = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata withKey:AVMetadataCommonKeyArtwork keySpace:AVMetadataKeySpaceCommon]; | |
NSImage *image = nil; | |
for (AVMetadataItem *item in artwork) { | |
if ([item.keySpace isEqualToString:AVMetadataKeySpaceID3]) { | |
image = [[NSImage alloc] initWithData:[item.value copyWithZone:nil][@"data"]]; | |
break; | |
} else if ([item.keySpace isEqualToString:AVMetadataKeySpaceiTunes]) { | |
image = [[NSImage alloc] initWithData:[item.value copyWithZone:nil]]; | |
break; | |
} | |
} | |
// got NSImage | |
}); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment