vendredi 12 février 2010

Searching the iPod library

If you want to search the iPod library, you need to create and configure a media query. A media query is an instance of the MPMediaQuery class and can be configured with the following two important pieces of information:

• Zero or one grouping scheme. You can group the media items that are returned from executing the query according to a specific grouping scheme. For example, you can ask the MPMediaQuery object to group the result set according to the artist.
• A query filter. A query filter consists of zero or more media property predicates.Foramedia item to be returned as a result of executing this query, it has to pass through all the media property predicates that make up the filter provided. If you specify no predicates, all media items will be returned from the query.

There are several class methods declared in the MPMediaQuery class that give you media queries with different groupings. For example, to create a media query that groups and sorts media items according to the album’s name, you can use the following class method:
+ (MPMediaQuery *)albumsQuery Other class methods include artistsQuery, genresQuery,and playlistsQuery.
Once you have configured the media query object, you can retrieve the result media items using the MPMediaQuery instance variable items. This instance variable is declared as follows:
@property(nonatomic, readonly) NSArray *items The items array holds instances of MPMediaItem class that match the query. If the result of the query is empty, the array will contain no elements. If, on the other hand, an error occurred during the execution of the query, the value of this property will be nil.
The following code fragment retrieves all songs in the iPod library, grouping them based on the artist name. It then logs specific values of each media item.

Aucun commentaire:

Enregistrer un commentaire