harryovers
harryovers

Reputation: 3138

ios get play count for items in the media library

I am currently trying to categorise a users music collection and the ability to get the users most played songs/artists would greatly improve the user experience in the app. Is it possible to get the play count? and how would I go about doing it

Upvotes: 7

Views: 1960

Answers (3)

Kristofer Sommestad
Kristofer Sommestad

Reputation: 3061

Should you want to find the user's most played track(s), you could:

  1. Store all media items (i.e. [[MPMediaQuery songsQuery] items]) and their properties in a database (i.e. Core Data), fetch them with an NSFetchRequest and sort the results with NSSortDescriptor.

  2. ...or use [[MPMediaQuery songsQuery] items] and sort the results on the MPMediaItemPropertyPlayCount property.

Option (1) is probably best, especially if you're looking to categorize the music collection (I guess (2) could be worse performance-wise too).

There's also a similar answer on SO to help answer your question.

Check out the Apple docs for more info on MPMediaQueries.

Upvotes: 3

objective_c_pro
objective_c_pro

Reputation: 925

If you use Core Data they have a lot of methods for you to use. Check this out: http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/CoreData/cdProgrammingGuide.html

Upvotes: 1

Jonathan Naguin
Jonathan Naguin

Reputation: 14766

MPMediaItem has the method:

- (id) valueForProperty: (NSString *) property

This method return the media property key that you want the corresponding value of. And one of the possibles values is MPMediaItemPropertyPlayCount:

The number of times the user has played the media item. Value is an NSNumber object representing an NSUInteger data type.

You can check the doc here and here.

Upvotes: 8

Related Questions