When I press the button the else statement only the else statement works, what am I missing from the if part? Every time I press the button the song plays and starts playing over itself. I'm trying to avoid that. I read the entire section in about the AVAudioPlayer, but I think I am missing something much more fundamental. Any help would be tremendously appreciated.
Code:
-(IBAction) playLick: (id) sender {
NSString *musicPath = [[NSBundle mainBundle] pathForResource:titleForButton ofType:@"mp3"];
theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicPath] error:NULL];
if (theAudio.playing) {
[theAudio pause];
[sender setTitle: @"Play" forState: UIControlStateHighlighted];
[sender setTitle: @"Play" forState: UIControlStateNormal];
}
else {
[theAudio play];
[sender setTitle: @"Pause" forState: UIControlStateHighlighted];
[sender setTitle: @"Pause" forState: UIControlStateNormal];
}
[musicPath release];
}