Hello to all. I am new to programming

. I am making my first iphone app with sounds, and i want when i press the sound button second time to stop and play at begin the sound, but now its playing two times at same time, this code i use, i add the if statement but it not working
Code:
-(IBAction)playSound:(id){
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"SoundFile" ofType:@"caf"]];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[player setNumberOfLoops:0];
[player prepareToPlay];
if (player.playing)
{
[player pause];
player.currentTime = 0;
}
[player play];
}
but it works fine in next code,
Code:
- (void)viewDidLoad {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"SoundFile" ofType:@"caf"]];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[player setNumberOfLoops:0];
[player prepareToPlay];
}
-(IBAction)play:(id)sender
{
if (player.playing) {
[player pause];
player.currentTime = 0;
}
[player play];
}
and the problem is with second code working only with 2 sounds , if i add more that 2 my app not working... help me please to make it work normal
Thanks!!