Take the 2-minute tour ×

So I'm trying to play a .wave file in iOS5, and I'm getting a warning, which is leading to SIGABRTs and generally not-working code.

NSURL *soundUrl = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Resources/Sounds/01_main_menu_list.wav", [[NSBundle mainBundle] resourcePath]]];
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
[_audioPlayer setDelegate:self];
[_audioPlayer play];

This is giving me an error "Sending "ViewController *const __strong" to parameter of incompatible type 'id '.

I have literally no idea why, I've followed a half-dozen examples and am coming up empty. I'd love a pointer in the right direction.

share|improve this question

2 Answers 2

This should work:

NSURL* soundUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"01_main_menu_list" ofType:@"wav"]]; 
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
audioPlayer.delegate = self;
[audioPlayer play];

If not, I think there's something wrong with the wav file. Maybe the encoding?

share|improve this answer
That got the file playing, but the warning is still there. Any idea what it means and how I can knock it on the head? It's been drilled into my head that a warning is just an error which hasn't crashed yet :) –  lukech Feb 8 '12 at 11:04
At which line of code do you get the warning, and what exactly does it say? –  Richard G. Nielsen Feb 8 '12 at 11:06
the delegate line, and it says exactly what I wrote above. "Sending "ViewController *const __strong" to parameter of incompatible type 'id '. –  lukech Feb 8 '12 at 11:16
Try to change audioPlayer.delegate = self; to audioPlayer.delegate = (id)self; –  Richard G. Nielsen Feb 8 '12 at 11:23
Also: See this question: stackoverflow.com/questions/6364911/… –  Richard G. Nielsen Feb 8 '12 at 11:26
up vote 0 down vote accepted

Turned out it was an issue with ARC releasing, I fixed it by adding a @property and @synthesize pair for the AVAudioPlayer in question, and declaring it as strong. It got rid of all of these errors, and played the file with no problems.

share|improve this answer

Your Answer


