我正在尝试检索我的 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.'
如果我尝试其他键,例如 MPMediaItemPropertyTitle
,MPMediaItemPropertyAlbumTitle
或 MPMediaItemPropertyArtist
工作正常。关于为什么我无法访问 MPMediaItemPropertyAlbumTrackCount
,我是否遗漏了什么。
最佳答案
您使用了 valueForKey:
这就是错误发生的原因。使用 valueForProperty:
如:
NSLog(@"Track Number %@", [mediaItem valueForProperty:MPMediaItemPropertyAlbumTrackCount]);
在MPMediaItem Class Referece苹果说:
You obtain metadata for a media item by calling the valueForProperty method with these property keys.
关于ios - MPMediaItem 此类与键的键值编码不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15499327/