I have this method to play an mp3:
- (void) playSound:(NSString*)sound{
NSString *path = [NSString stringWithFormat:@"%@/%@",
[[NSBundle mainBundle] resourcePath],
sound];
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:filePath error:nil];
[player prepareToPlay];
[player play];
}
everytime I call this method I get a new string “sound” and then I must alloc everytime this AVAudioplayer “player”; I want release it when I stop it or when it finish…is it possible?
Try the below instruction
yourViewController.h
yourViewController.m file for add function
Declare the AVAudioPlayer Object below code
Thanks..!