从 iPod 库中获取播放次数最多的曲目 (MPMediaQuery)
我需要使用 iPhone 应用程序从 iPod 库中找出播放次数最多的 25 首歌曲。我正在使用 MPMediaQuery。
一种解决方案是循环遍历所有曲目,并通过 MPMediaItemPropertyAlbumTrackCount 进行比较。但我认为这有点低效。有没有办法直接获取最常播放的项目播放列表?
I need to get out the 25 most Played Songs out from my iPod Library with my iPhone app. i am using a MPMediaQuery.
One solutions would be to loop through all tracks and them comparing by MPMediaItemPropertyAlbumTrackCount. But i think thats a bit unefficient. Is there a way to directly get the Most Played items playlist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(2)
您可以使用 NSSortDescriptor 对播放次数最多的歌曲进行排序
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
NSSortDescriptor *sorter = [NSSortDescriptor sortDescriptorWithKey:MPMediaItemPropertyPlayCount 升序:NO];
NSArray *sortedSongsArray = [[所有项目]sortedArrayUsingDescriptors:[NSArray arrayWithObject:sorter]];
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我认为您正在寻找 MPMediaItemPropertyPlayCount 而不是 MPMediaItemPropertyAlbumTrackCount。 MPMediaItemPropertyAlbumTrackCount 是歌曲在专辑中出现的曲目编号。
MPMediaItemPropertyPlayCount 不幸的是不能用于通过 MPMediaQuery 进行查询,因为它是用户定义的属性。
最好的选择是,当您的应用首次打开时,将所有播放计数存储在 Core Data 等数据库中,并在用户的库发生更改时通过注册通知来更新它。
I think you are looking for MPMediaItemPropertyPlayCount not MPMediaItemPropertyAlbumTrackCount. MPMediaItemPropertyAlbumTrackCount is the track number of the song as it appears in its album.
MPMediaItemPropertyPlayCount unfortunately cannot be used for making queries with MPMediaQuery since it is a user-defined property.
Your best option is to store all the play counts in a database like Core Data when your app is opened for the first time and update it by registering for notifications when the user's library changes.