我正在製作一個音板應用程序,我使用的聲音持續時間超過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];
}