MPMediaItem此类不是密钥值编码兼容的密钥

时间:2013-03-19 12:19:20

标签: ios mpmediaitem

我试图检索iPod库中歌曲的曲目编号。

基本上我已经查询了所有相册如下:

NSArray *albums = [MPMediaQuery albumsQuery].collections;

检索了一张专辑:

MPMediaItemCollection *album = self.albums[0];

迭代歌曲并尝试记录曲目编号

for (MPMediaItem *mediaItem in self.album.items)
{
    NSLog(@"Track Number %@", [mediaItem valueForKey:MPMediaItemPropertyAlbumTrackCount]);
}

但是这给了我以下错误

Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<MPConcreteMediaItem 0x1cd818d0> valueForUndefinedKey:]: this class is 
not key value coding-compliant for the key albumTrackCount.'

如果我尝试其他密钥,例如MPMediaItemPropertyTitleMPMediaItemPropertyAlbumTitleMPMediaItemPropertyArtist正常工作。有什么我不知道为什么我无法访问MPMediaItemPropertyAlbumTrackCount

1 个答案:

答案 0 :(得分:8)

您使用了valueForKey:这就是错误发生的原因。使用valueForProperty:之类的:

NSLog(@"Track Number %@", [mediaItem valueForProperty:MPMediaItemPropertyAlbumTrackCount]);

MPMediaItem Class Referece Apple中说:

  

通过调用valueForProperty获取媒体项的元数据   使用这些属性键的方法。