0

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.

skolima
  • 31,963
  • 27
  • 115
  • 151
Luke
  • 9,512
  • 15
  • 82
  • 146

2 Answers2

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?

Richard G. Nielsen
  • 1,221
  • 10
  • 13
  • 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 :) – Luke Feb 08 '12 at 11:04
  • At which line of code do you get the warning, and what exactly does it say? – Richard G. Nielsen Feb 08 '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 '. – Luke Feb 08 '12 at 11:16
  • Try to change audioPlayer.delegate = self; to audioPlayer.delegate = (id)self; – Richard G. Nielsen Feb 08 '12 at 11:23
  • Also: See this question: http://stackoverflow.com/questions/6364911/handling-app-delegates-and-switching-between-views – Richard G. Nielsen Feb 08 '12 at 11:26
0

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.

Luke
  • 9,512
  • 15
  • 82
  • 146