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

2

1

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?

Raisin answered 27/9, 2011 at 14:38 Comment(0)
H
4

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.

Handtohand answered 29/10, 2011 at 14:10 Comment(0)
B
1

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

Bridgettebridgewater answered 17/10, 2013 at 19:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.