我正在制作一个音板应用程序,我使用的声音持续时间超过30秒。我通过在IB中将我的动作与“降落”事件连接起来播放声音,但是一旦开始播放,声音就会继续播放。我在某个按钮上连接了一个“touch cancel”&“touch up outside”事件,该事件应该会停止声音,但由于某种原因它不会。 任何人都可以提供解决我的问题吗?音板应用程序:只要用户按下按钮播放声音
---编辑--- 这里是我的代码:
-(IBAction)playSound:(id)sender {
NSString *soundFile;
soundFile = [[NSBundle mainBundle] pathForResource:@"testSound" ofType:@"mp3"];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundFile] error:nil];
audioPlayer.volume = volumeSlider.value;
audioPlayer.numberOfLoops = -1;
[audioPlayer prepareToPlay];
[audioPlayer play];
}
-(IBAction)stopSound:(id)sender {
[audioPlayer stop];
}