Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 733
harryovers Avatar asked Jun 29 '12 11:06

harryovers


2 Answers

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.

like image 101
Jonathan Naguin Avatar answered Sep 22 '22 05:09

Jonathan Naguin


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.

like image 40
Kristofer Sommestad Avatar answered Sep 19 '22 05:09

Kristofer Sommestad