我在表格视图单元格上放了一个按钮,当按下按钮时它会播放声音,当我按下按钮时它会停止声音。但是按下另一个单元格上的另一个按钮,它不会播放另一个声音,而另一个仍在播放。我希望当在另一个表格单元格中按下另一个按钮时,它会停止播放声音。
这是我的代码
.h 文件
我在@interface 括号 AVAudioPlayer *talkSound; 上输入这个
.m
NSString *myExamplePath = [[NSBundle mainBundle] pathForResource:@"kumusta" ofType:@"m4a"];
if (talkSound.playing) {
[talkSound stop];
[talkSound release];
}
talkSound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:myExamplePath] error:NULL];
talkSound.delegate = self; /*with this here it says theres no delegate so i go an add AVAudioPlayerDelegate and i get tons of errors of connot find protocol declaration*/
[talkSound play];