Reputation: 2999
I want to show the list of all songs from the user's ipod in a list inside my application. When the user clicks a song I want to store the name of the this song.
I also later want to grab the name of that song and play it (but not right away).
Any ideas where to start for this? I know it is probably somewhere in the Media.Player framework but I can't seem to figure out how to actual view the list of songs from inside the application
Upvotes: 0
Views: 3765
Reputation: 130193
You can call up the MPMediaPickerController using this:
- (IBAction) selectSong: (id) sender
{
MPMediaPickerController *picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = NO;
picker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");
[self presentModalViewController: picker animated: YES];
}
Then you can add the songs that were selected to your own array using something like this.
Note: You will access meta-data information from each track using valueForProperty
.
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
[self dismissModalViewControllerAnimated: YES];
someMutableArray = [mediaItemCollection mutableCopy];
}
Then this is kind of self explanatory but necessary:
- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker
{
[self dismissModalViewControllerAnimated: YES];
}
For more information visit Apple's iPod Library Access Programming Guide
Upvotes: 2