First, if AVAudioPlayerstill playing, stop it:
if([snd isPlaying]){
[snd stop];
}
Then recreate a new one AVAudioPlayerwith a new URL. My first suggestion about reactivating the player will not work . You need to create a new instance.
snd = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSBundle mainBundle]URLForResource:@"sound_b" withExtension:@"wav"] error: nil];
[snd play]
The best solution is to use AVQueuePlayer for several sounds:
AVPlayerItem *item1 = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"sound_a"]];
AVPlayerItem *item2 = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"sound_b"]];
AVQueuePlayer *player = [[AVQueuePlayer alloc] initWithItems:@[item1, item2]];
[player play];
[...]
[player advanceToNextItem];
source
share