开发者

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

开发者 https://www.devze.com 2023-04-08 22:55 出处:网络
I need to get out the 25 most Played Songs out from my iPod Library with my iPhone app. i 开发者_Go百科am using a MPMediaQuery.

I need to get out the 25 most Played Songs out from my iPod Library with my iPhone app. i 开发者_Go百科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?


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.


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]];

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号