0

So this is the code I have:

At the press of a button:

-(void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
    [self dismissModalViewControllerAnimated:YES];
self.selectedSong = mediaItemCollection;
    NSLog(@"Selected song: %@", self.selectedSong);
}

Later on:

-(void)waitUntilSpeechIsDone {
    NSLog(@"Test");
    if ([audio isEqualToString:@"Music"]) {
    if ([musicWhenToStart isEqualToString:@"Before"]) {
        NSLog(@"Test");

        NSLog(@"Selected song: %@", self.selectedSong);
        [self.musicPlayer stop];
        [self.musicPlayer setQueueWithItemCollection:self.selectedSong];
        [self.musicPlayer play];
    }
    }   
}

It's defined as:

@interface RewriteViewController : UIViewController <MPMediaPickerControllerDelegate> {

    MPMediaItemCollection *selectedSong;

}
@property(nonatomic,retain) MPMusicPlayerController *musicPlayer;
@property(nonatomic,retain) MPMediaItemCollection *selectedSong;


MPMediaItemCollection *selectedSong;

Then both are synthesized in the .m file.

Ok, so it gets through the first half fine. The NSLog returns something like "Selected song: " Then NSLog returns "Test", (i put that there so i know it's got that far in case it crashes at the next line for some reason). Then when it gets to the next line it returns "Selected song: (null)".

Any ideas why?

EDIT: Both are released in dealloc.

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Andrew
  • 15,935
  • 28
  • 121
  • 203

1 Answers1

0

Looking at your interface file, it appears you are declaring MPMediaItemCollection *selectedSong; twice :/ I'm not sure if this was a typo in posting the question, but that might have something to do with it. You crash is most likely related to selectedSong being released at some point when you don't expect it, and an bad declaration could be causing that.

raidfive
  • 6,603
  • 1
  • 35
  • 32
  • I commented out the last one. It still returns as null. – Andrew Feb 04 '11 at 20:33
  • And you aren't releasing `selectedSong` or mucking with it anywhere else in your application? This is all within the same class, correct? `RewriteViewController` – raidfive Feb 04 '11 at 21:04
  • The app also has the option of doing the following code, but it's always 1 or the other. Don't have problems doing it this way. And it's all in RewriteViewController, yes. `if ([musicWhenToStart isEqualToString:@"Start"]) { [musicPlayer stop]; NSLog(@"selected song: %@", selectedSong); [musicPlayer setQueueWithItemCollection:self.selectedSong]; [musicPlayer play]; }` – Andrew Feb 04 '11 at 22:13
  • hmm, I'd try running your app against the debugger and tracking the value of `selectedSong` through the entire application life-cycle. Make sure it isn't being invalidated/released somewhere. – raidfive Feb 05 '11 at 02:38