iphone-AVAudio Player Crashes
        Posted  
        
            by 
                user2779450
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user2779450
        
        
        
        Published on 2013-09-20T15:14:11Z
        Indexed on 
            2013/11/04
            15:54 UTC
        
        
        Read the original article
        Hit count: 448
        
I have an app that uses an avaudio player for two things. One of them is to play an explosion sound when a uiimageview collision is detected, and the other is to play a lazer sound when a button is pressed. I declared the audioplayer in the .h class, and I call it each time the button is clicked by doing this:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"/lazer"
                                     ofType:@"mp3"]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc]
               initWithContentsOfURL:url
               error:&error];
if (error)
{
    NSLog(@"Error in audioPlayer: %@",
          [error localizedDescription]);
} else {
    [audioPlayer prepareToPlay];
}
[audioPlayer play];
This works fine, but after many uses of the game, the audio will stop play when i hit the button, and when a collision is detected, the game crashes. Here is my crash log:
2013-09-18 18:09:19.618 BattleShip[506:907] 18:09:19.617 shm_open failed: "AppleAudioQueue.41.2619" (23) flags=0x2 errno=24 (lldb)
Suggestions? Could there be something to do with repeatedly creating an audio player? Alternatives maybe?
© Stack Overflow or respective owner