I plan to use multiple AVAudioPlayers to play different audio files simultaneously. They are triggered by user-initiated events. I am using ARC for the first time, and there is not much documentation out there as to how ARC might apply to setting up AVAudioPlayers (Apple’s sample code is pre-ARC, as are most tutorials I can find).
The app works fine with one AVAudioPlayer instance, but throws a SIGABRT once a second is added. My guess is that it has something to do with the player instances being released prematurely by ARC, but am not sure how to prevent this.
Code is as follows:
@interface LocationTracker : UIViewController <AVAudioPlayerDelegate> {
AVAudioPlayer *mainLoopPlayer;
AVAudioPlayer *sea1Player;
}
@property (strong, nonatomic) AVAudioPlayer *mainLoopPlayer;
@property (strong, nonatomic) AVAudioPlayer *sea1Player;
@end
implementation (in viewDidLoad):
NSURL *mainLoopURL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"wind" ofType:@"aiff"]];
self.mainLoopPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:mainLoopURL error:nil];
mainLoopPlayer.numberOfLoops = -1;
mainLoopPlayer.delegate = self;
[mainLoopPlayer prepareToPlay];
NSURL *sea1URL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"sea1" ofType:@"aiff"]];
self.sea1Player = [[AVAudioPlayer alloc] initWithContentsOfURL:sea1URL error:nil];
sea1Player.numberOfLoops = -1;
sea1Player.delegate = self;
[mainLoopPlayer prepareToPlay];
Any help much appreciated.
Okay, found the problem, and it wasn’t to do with memory management, but instead the use of a referenced folder to link to the audio files.
I have previously used referenced folders to store images in without any problems, but this is a no-go when dealing with multiple audio files, apparently.