ユーザーが「OK」ボタンを押したときに停止したいサウンドループをアプリで作成しUIAlertView
ました。
ただし、2つの問題があります。
初め
ブレークポイントをオンにして、すべての例外にブレークポイントを設定すると、例外が表示され[audioPlayer play]
ますが、ログにエラーは表示されず、音が出ないことを除いて、例外を「F8-ing」してもアプリはクラッシュしません。
2番
私が抱えているもう1つの問題は、ユーザーが「OK」ボタンをタップした後にオーディオファイルが停止せず、ブレークポイントを介して[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];
}
}
}
これを修正するために私にできることを教えてください。