我想获得专辑图片/歌曲封面。可能吗?我正在使用AVPlayer进行音频流传输,如果歌曲包含它,我需要获得专辑封面。喜欢在iTunes中。
SOLUTION:
UIImage *img = nil;
NSArray *metadata = _avplayer.currentItem.asset.commonMetadata;
for(AVMetadataItem *item in metadata){
if([item.commonKey isEqualToString:@"artwork"]){
NSData *data = item.value[@"data"];
img = [UIImage imageWithData:data];
return img;
}
}
return img;
答案 0 :(得分:1)
你应该尝试这个,但我使用MPMusicPlayer:
musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
currentItem = [musicPlayer nowPlayingItem];
if (currentItem == nil) {
//Not playing
}
else
{
NSString *name = [currentItem valueForProperty:@"title"];
int length = [name length];
if (length > 30) {
name = [name substringWithRange:NSMakeRange(0, 30)];
name = [name stringByAppendingString:@"..."];
}
NSString *album = [currentItem valueForProperty:@"albumTitle"];
int lengthAl = [album length];
if (lengthAl > 30) {
album = [album substringWithRange:NSMakeRange(0, 30)];
album = [album stringByAppendingString:@"..."];
}
NSString *artist = [currentItem valueForProperty:@"artist"];
int lengthAr = [artist length];
if (lengthAr > 30) {
artist = [artist substringWithRange:NSMakeRange(0, 30)];
artist = [artist stringByAppendingString:@"..."];
}
MPMediaItemArtwork *artworkPrev = [currentItem valueForProperty:@"artwork"];
if (artworkPrev != nil)
{
UIImage *img = [artworkPrev imageWithSize:CGSizeMake(65, 65)];
UIImageView *imgNew = [[UIImageView alloc] initWithImage:img];
imgNew.frame = CGRectMake(-15,-20, 65, 65);
}
}
正如您所看到的,我使用的是NSMakeRange,我只是将它用在我的应用程序中。我希望能帮到你
答案 1 :(得分:0)
如果您的文件格式正确,即MP3,您可以将文件的数据加载到ID3标记解析器中。 Here's an example of one.它是为OS X制作的,但它看起来应该很容易移植到iOS。