我在用户的文档目录中有几个MP3文件,我希望能够获取并显示ID3艺术品标签。我尝试过使用NSURLAsset,但我不确定如何将其转换为UIImage或UIImageView!
谢谢!
答案 0 :(得分:3)
您必须使用AVAsset类:
例如:
NSString *mp3Path = [[NSBundle mainBundle] pathForResource:@"audio-file" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:mp3Path];
AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
for (NSString *format in [asset availableMetadataFormats]) {
for (AVMetadataItem *item in [asset metadataForFormat:format]) {
if ([[item commonKey] isEqualToString:@"artwork"]) {
NSData *data = [(NSDictionary *)[item value] objectForKey:@"data"];
UIImageView *img = [[[UIImageView alloc] initWithImage:[UIImage imageWithData:data]] autorelease];
[self.view addSubview:img];
continue;
}
NSLog(@"%@", item);
}
}
NSLog(@"> Duration = %.2f seconds", CMTimeGetSeconds(asset.duration));