我在我的应用程序中制作了一个声音循环,当用户按下出现的“确定”按钮时,我想停止UIAlertView
它。
我有两个问题:
第一的
当我打开断点并为所有异常设置断点时,会出现异常[audioPlayer play]
但日志上没有显示错误,并且应用程序不会在通过异常“F8-ing”后崩溃,除非没有声音。
第二
我遇到的另一个问题是用户点击“确定”按钮后音频文件不会停止,并且断点显示它确实读取了[audioPlayer stop]
调用。我不知道是什么导致了这些错误,我所做的似乎无济于事。
代码
AVAudioPlayer *audioPlayer;
-(void)done {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Timer Done" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alert show];
[self playAlert];
}
-(void)playAlert {
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Alarm" ofType:@"caf"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
audioPlayer.numberOfLoops = -1; //infinite
[audioPlayer play];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
if ([audioPlayer isPlaying]) {
[audioPlayer stop];
}
}
}
请让我知道我能做些什么来解决这个问题。