Quote:
Originally Posted by Akshay Shah
Hi all..
I need some help regarding audio playing...
I have 10 sound files in my bundle.
So i need to play them one after another..
How can i do that?
|
Create an array, play the first item in array, when done it calls the audioPlayerDidFinishPlaying and then play the next item in the array....
Works like a charm. I have an App, iNtervalTunes, that uses this technique and it works.
Some of this code is relevant, some isn't...basically create an array and then keep playing items in array until done, and then when each one is done, this method is called. Don't forget that your class has to implement the audio player's delegate. They play one after the other.
James A. Brannan
iPhone SDK Programming, A Beginner's Guide.
Code:
// not compilable, mixed together to give you the idea...
@interface WorkoutVoiceHolder : NSObject <AVAudioPlayerDelegate>
NSMutableArray * theSoundQueue;
@property (nonatomic,retain) NSMutableArray * theSoundQueue;
NSMutableArray * soundsQueue = [[[NSMutableArray alloc] init] autorelease];
[((AVAudioPlayer*)[self.theSoundQueue objectAtIndex:0]) play];
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
[player release];
////////NSLog(@"in audioPlayerDidFinishPlaying...");
if([self.theSoundQueue count] > 0)
{
[self.theSoundQueue removeObjectAtIndex:0];
}
if([self.theSoundQueue count]< 1)
{
AudioSessionSetActive(false);
[[NSNotificationCenter defaultCenter] postNotificationName:@"audioPlayerNotPlaying" object:nil];
isCurrentlyPlaying = NO;
return;
}
[((AVAudioPlayer*)[theSoundQueue objectAtIndex:0]) play];
}