views:

40

answers:

1

Hello. I'm diving into iOS development and have been slowly building my own alarm clock app to learn how to develop on the platform. I want my alarm clock to allow me to display a list of songs on my iOS device, choose only one, and have it play when the alarm fires. I've figured out how to use the MPMediaPicker to display the list of songs and allow the user to select songs that are ultimately added to a MPMediaItemCollection that is used to tell the MPMediaPlayer object which songs to play. Here's the code for all that...

- (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];
[picker release]; }

Store the song...

- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {

[self dismissModalViewControllerAnimated: YES];
selectedSongCollection=mediaItemCollection; }

Dismiss the picker...

- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker {

[self dismissModalViewControllerAnimated: YES]; }

Now this code allows you to choose a song and play it at any point while the app is running. My questions are...

  1. How can I store that song information in the userInfo dictionary that's included as part of the local notification that represents my alarm being triggered?
  2. my other question is, once I'm able to retrieve that song info from the local notification, how do I play it?

I'm so new to all this that I'm really having a hard time understanding how this would work. Thanks so much in advance for your help!