My code:
- (void)metadata {
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:self.fileURL options:nil];
NSArray *artworks = [AVMetadataItem metadataItemsFrom
As Ryan Heitner pointed out in a comment to Andy Weinstein, the way to retrieve the binary artwork data from the AVMetadataKeySpaceID3
has changed somewhere from IOS7 to IOS8. Casting blindly item
to NSDictionary
will crash in the ID3 case nowadays. To make code bullet proof just check dataValue, otherwise the Classes. In fact today item.value
points to item.dataValue
and has the NSData
class.
- (UIImage*)imageFromItem:(AVMetadataItem*)item
{
NSData* data=nil;
if (item.dataValue!=nil) {
data=item.dataValue;
} else if ([item.value isKindOfClass:NSData.class]) { //never arrive here nowadays
data=(NSData*)item.value;
} else if ([item.value isKindOfClass:NSDictionary.class]) { //never arrive here nowadays...
NSDictionary* dict=(NSDictionary*)item.value;
data=dict[@"data"];
}
if (data==nil) {
return nil;
}
return [UIImage imageWithData:data];
}