Hi,
I'm trying to setup a simple button that will allow me to play sound and stop a previous sound file. But unfortunately I have a problem with the way I have done this, when I press the button the audio starts but then if i press it again another instance starts and the files plays again.
Please can someone point me in the right direction? Thank you in advance.
CODE:
- (IBAction)soundFile {
NSString *playerPath = [[NSBundle mainBundle] pathForResource:@"sound_file" ofType:@"m4a"];
AVAudioPlayer* player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath

layerPath] error:NULL];
player.delegate = self;
[player stop];
[player play];
}
- (IBAction)soundFileTwo {
NSString *playerPath = [[NSBundle mainBundle] pathForResource:@"sound_file" ofType:@"m4a"];
AVAudioPlayer* player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath

layerPath] error:NULL];
player.delegate = self;
[player stop];
[player play];
}