tags:

views:

2191

answers:

4

I want to play multiple MP3 files, in sequence (one after the other) , using AVAudioPlayer. I tried it, and it stops after playing the first MP3. However, if I go into debugger, it works fine.. any ideas? I read somewhere AVAudioPlayer plays audio in the background.. how do I prevent it from doing this? Vas

+1  A: 

It would help to see your code. Somethings to look at - are you using one AVAudioPlayer per sound?

When you play mp3 files only one can play at a time so any over lap may not give expected results.

Not sure why the debugger would make a difference unless you mean in the simulator too. Maybe the simulator can play multiple mp3 files concurrently (since that is a result of mp3 decoding hardware in the iPhone).

Well more info will help us find a solution so feel free to post som code.

John Fricker
A: 

The following code ONLY plays one sound - ignores the other. Im very new to IPHONE sdk - ive scoured the web looking for a working example - Please GURUS of OBJC please help a poor Padawan learner. IPhone SDK 2.2.1

*

  (void)viewDidLoad {

  path2 = [[NSBundle mainBundle] pathForResource:@"alien" ofType:@"caf"];

  oplayer=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path2] error:NULL];

  oplayer.delegate = self;

  path = [[NSBundle mainBundle] pathForResource:@"Lotus" ofType:@"caf"];

  player=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

  player.delegate = self;

  [oplayer play];

  [player play];

}

Did you ever solve this? If so, if you switch alien and Lotus does the other file play but the first one not play?
Jeffrey Berthiaume
A little late to the party... but you have to do this using `audioPlayerDidFinishPlaying`
iWasRobbed
+1  A: 

Use one AVAudioPlayer per sound.

+3  A: 

You should use one AVAudioPlayer and let it play the next file in the sequence by implementing audioPlayerDidFinishPlaying:successfully:. You could use an array with the filenames, keeping track of your current position with a simple integer that you increment on every audioPlayerDidFinishPlaying..

StijnSpijker
I'm having a problem with this approach because the event gets triggered even when scrubbing (changing play location) on the current track. Gene and John's suggestion to use one AVAudioPlayer per sound file might be a good alternative.
paul_sns