Вы должны разделить эти два процесса на этот
`- (void)initSound {
NSString *path = [[NSBundle mainBundle] pathForResource:@"3" ofType:@"wav"];
NSError *error = nil;
threeAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
if (error)
NSLog(@"%@",[error localizedDescription]);
threeAudio.numberOfLoops = -1;
threeAudio.delegate = self;
[threeAudio prepareToPlay];
[threeAudio play];
}
-(IBAction)threeSound:(id)sender:(UIButton *)sender{
if (sender.selected) {
[threeAudio pause];
} else {
threeAudio.currentTime = 0;
[threeAudio play];
}
sender.selected = !sender.selected;
}`
Обратите внимание, что initSound должен вызываться в какой-то момент, если вы хотите запустить звук только кнопкой ... затем добавьте
if (!threeAudio) {
[self initSound];
}
в начале IBAction
Вот мой совет;)