1

当我使用 MediaPicker 时,我想要带有歌曲的图像。

代码:

 NSMutableArray *arr = [NSMutableArray arrayWithArray:mediaItemCollection.items];
for (int i =0; i<=[arr count]-1; i++) {
    MPMediaItem *selectedSong = [[mediaItemCollection items] objectAtIndex:i];

    titleString = [selectedSong valueForProperty:MPMediaItemPropertyTitle];
}

titleString是我的阵列。

4

1 回答 1

0

试试这个:

NSMutableArray *arr = [NSMutableArray arrayWithArray:mediaItemCollection.items];

for (int i =0; i<=[arr count]-1; i++) {
    MPMediaItem *selectedSong = [[mediaItemCollection items] objectAtIndex:i];

    titleString = [selectedSong valueForProperty:MPMediaItemPropertyTitle];

    MPMediaItemArtwork *artWorkItem = [selectedSong valueForProperty:MPMediaItemPropertyArtwork];
    UIImage *coverImage = NULL;

    if(artWorkItem)
         coverImage = [artWorkItem imageWithSize:CGSizeMake(100, 100)];

    if(coverImage)
        myImageView.image = coverImage;
    else
    {
        NSLog(@"No album Artwork!!!");
        myImageView.image = [UIImage imageNamed:@"default"];
    }
}
于 2013-07-12T07:40:45.990 回答