Quote:
Originally Posted by dlaro
i can see the reference to the AVAudioPlayer in the help docs but cannot decipher what it's saying. i am pretty new at the dev game. any chance you have any sample code to show how would integrate with my existing code?
thanks!
|
Sigh...
Move your audio player object from a local variable to an instance variable in the class that contains your playSoundid method. Then add an @property (nonatomic, retain) statement in the header file, and and @synthesize statement. If you don't know how to do those things, go find Brian Slick's guide to properties in the tutorials section.
You might also want to read the memory management guide that is in the XCode docs. It's pretty easy to follow, and absolutely critical that you understand. There are a few simple rules to follow with handling memory in Cocoa, and if you follow them, you won't have any problems with leaking memory or over-release crashes. If you don't learn the rules early and follow them scrupulously, you will write apps that crash unexpectedly, run out of memory, and will get very frustrated.
Now, the 2 lines you need to add to your code:
Code:
-(IBAction)playSoundid)sender{
//AVAudioPlayer *audioPlayer;
NSString *path = [[NSBundle mainBundle]pathForResource:@"bazzel1" ofType:@"wav"];
self.audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL] autorelease];
audioPlayer.delegate = self;
[audioPlayer play];
}
Then add a method like this to your class:
Code:
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
//Create and play your second sound, since the first sound is done playing.
}
That last method is a delegate method. By setting your class up as the delegate for the audio player, the audio player will call any of the methods in the AVAudioPlayerDelegate Protocol that you define.