I'm looking for a way to programmatically (i.e., not via UI) access a users iTunes music library from my iOS app.
(Yes, I am aware that Apple discourages alternate iPod-interface apps. That's not the question :)
What I'd like to do is:
- Gather a list of song names.
- Have my app make an anagram of them.
- Have the user guess the original song name.
- If they guess right, I play a snippet of the song.
(That's not my real application, but it contains all the pieces I need.) The parts that I'm asking about are: How to get a list of song names and, given a song name, how to get the media to play it?
I think that AVAssetReader is what will let me play a song, once I have its name, so I can look that up on my own (bonus points for pointers there, though!) -- so the bottom-line question is: How to get a list of song titles from a user's iTunes Library in iOS?
You'll want to use MPMediaQuery to get an NSArray of all the songs. Check out this link.
To play the song, I would suggest using AVPlayer.