On iOS, can I access the iTunes song list?

I'm looking for a way to programmatically (i.e. not through an interface) access the iTunes users music library from an iOS application.

(Yes, I know that Apple is discouraging alternative applications for the iPod interface. This is not a question :)

I would like:

  • Make a list of song names.
  • Ask my app to make them anagram.
  • Ask the user to guess the original name of the song.
  • If they guess, I play a piece of the song.

(This is not my real application, but it contains all the parts I need). The parts I'm asking for are: How to get a list of song names and, given the name of the song, how to get media to play?

I think that AVAssetReader is what will allow me to play a song as soon as I have my own name, so I can watch it on my own (bonus points for pointers there, though!), So the bottom question is: How to get a list of song names from Library User on iOS?

+8
ios itunes
source share
2 answers

You will want to use MPMediaQuery to get the NSArray of all the songs. Check out this link.

To play a song, I would suggest using AVPlayer.

+6
source share

Check the documents , especially the section "Getting Media Elements Programmatically".

If the media selector does not provide the required control, you can use the database access classes from this API. These classes allow you to create arbitrarily complex queries. You could, for example, get all the songs in a particular genre whose names include a specific word or phrase.

Using software access is a two-step process:

Configure the request. Ask for the appropriate media items. A media query is a description of what to retrieve from an iPod, and how these seized items should be organized. It has two properties to configure:

A filter is a description of what to retrieve. The filter is optional; The filter request matches the entire iPod library. A grouping type is an optional key that determines how to use multimedia elements for extracted collections. Scaling is a bit more, the filter can be as simple or complex as your application requires. This consists of one or more instances of the media property predicate. a predicate of properties of an environment is a statement of a logical condition for checking each element of multimedia. Items matching the filter are retrieved from the iPod library when prompted.

The optional type of grouping determines the organization and sorting of collections, as well as the sorting of media elements in each collection. For example, using the β€œalbum” grouping type results in returned media items grouped by album, with each song sorted in order.

+6
source share

All Articles