Why is the sound not playing?

138 views Asked by At

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.

1

There are 1 answers

4
raidfive On

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.