Friday, 6 September 2013

AVAudioPlayer issues with playing sound in background

AVAudioPlayer issues with playing sound in background

I am new to programming and I have a small issue which I'm sure should be
easily resolved if I just knew where I was going wrong.
I have music playing when my app loads, which loops, and I have 4 buttons
on the screen. 3 of them are fine but when I press the play button to play
the game the app crashes.
When the app stops it shows a breakpoint beside:
- (IBAction)buttonClickedPlay {
gameState = kStateRunning;
Here is my AudioPlayer code:
[NSTimer scheduledTimerWithTimeInterval:1.0/60 target:self
selector:@selector(gameLoop) userInfo:nil repeats:YES];
NSURL *url = [NSURL fileURLWithPath:[NSString
stringWithFormat:@"%@/test.wav", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;
if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];

No comments:

Post a Comment