我是如何使用MediaPicker iPhone获得图像之歌的

时间:2013-07-12 07:20:08

标签: iphone

当我使用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是我的阵列。

1 个答案:

答案 0 :(得分: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"];
    }
}