Loading

Sunday, June 13, 2010

Play Sound Effect

1---> Import AVFoundation.framework
2---> -(void) PlayMusicSound: (NSString *)SoundFileName ForNumberOfLoops:(NSInteger)numLoops Extension:(NSString *)SoundExtension; // in .h file
3---> #import // in .m file
4---> -(void) PlayMusicSound: (NSString *)SoundFileName ForNumberOfLoops:(NSInteger)numLoops Extension:(NSString *)SoundExtension
{
//[player stop];
//self.SoundPlaying = SoundFileName;
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: SoundFileName ofType: SoundExtension];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];

AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: nil];
player.numberOfLoops = numLoops;
[fileURL release];

[player play];
[player setDelegate: self];
}

5---> call [self PlayMusicSound:@"Bite" ForNumberOfLoops:0 Extension:@"wav"];

No comments:

Post a Comment