1
votes

I am using AVAudioPlayer to make an MP3 player. I have multiple MP3 sounds and would like to play these sounds one by one. Following is the logic of my app:

///// For playing 1st sound

mp3Player = [[AVAudioPlayer alloc] initWithContentsOfURL:url1 error:nil];
[mp3Player  prepareToPlay];
[mp3Player play];


///// For playing 2nd sound
mp3Player = nil;
mp3Player = [[AVAudioPlayer alloc] initWithContentsOfURL:url2 error:nil]; 
[mp3Player  prepareToPlay];
[mp3Player play];


///// For playing 3rd sound
mp3Player = nil;
mp3Player = [[AVAudioPlayer alloc] initWithContentsOfURL:url3 error:nil];
[mp3Player  prepareToPlay];  
[mp3Player play];

etc...

Just would like to know: I nil out the player and alloc AVAudioPlayer before playing the next sound. Is there any performance (speed) or memory (leak) concern in this logic? (I am using ARC). If so, is there any way to alloc AVAudioPlayer just ONE time, and to accept diffrent URLs pointing to those sounds? Thanks a lot in advance.

1

1 Answers

4
votes

I think below link may help you:

How to play multiple audio files in sequence by loop in AVAudioPlayer?

In which audioPlayerDidFinishPlaying is used to play next song after one finishes.