Getting the most played track out of the iPod library (MPMediaQuery)

给你一囗甜甜゛ 提交于 2019-12-13 18:51:39

问题


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?


回答1:


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.




回答2:


you can use NSSortDescriptor to sort the most played songs

MPMediaQuery *everything = [[MPMediaQuery alloc] init]; NSSortDescriptor *sorter = [NSSortDescriptor sortDescriptorWithKey:MPMediaItemPropertyPlayCount ascending:NO]; NSArray *sortedSongsArray = [[everything items] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sorter]];



来源:https://stackoverflow.com/questions/7570969/getting-the-most-played-track-out-of-the-ipod-library-mpmediaquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!