In my Project I have a table View.. which has having accessory buttons.
So when I click on button the sound will play...
if the sound is already playing then it will stop...
here is my code....
-(void)playAudio:(int)index
{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:
[NSString stringWithFormat:@"%@",soundListArray[index]] ofType:@"mp3"];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundFilePath] error:nil];
audioPlayer.numberOfLoops = 0;
audioPlayer.delegate = self;
[audioPlayer play];
}
I am also stopping it when player has finished.
I already searched a lot...
i also applied this after every stop but it won't affect....
audioPlayer = nil;
audioPlayer.delegate = nil;