嗨,有谁知道如何向按钮添加音频我已经添加了框架创建了一个放置声音的动作,但是当我按下按钮时没有声音播放?
这是我到目前为止所做的
-(void)buttonSound{
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/ButtonSound.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer2 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer2.numberOfLoops = -1;
[audioPlayer2 play];
}
- (IBAction)backToMenu:(id)sender {
[self buttonSound];
[self.navigationController popViewControllerAnimated:YES];
}