2009-08-07 86 views
0

我在桌子视图单元格上放置了一个按钮,当它们被按下时播放声音,当我按下它停止声音时。但按另一个单元格上的另一个按钮时,它不会播放另一个声音,而另一个仍在播放。我希望当另一个表格单元格中的另一个按钮被按下时,它将停止播放声音。我把一个按钮放在表格视图单元格上,当它们被按下时播放声音,但

这里是我的代码

.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]; 

回答

1

我不知道这是不是问题,但你并不需要释放,每次重新分配AVAudioPlayer。只是停止和启动它应该做工精细,如:

if (talkSound.playing) { 
    [talkSound stop]; 
} 
[talkSound play]; 

然后,你可以分配/初始化的AVAudioPlayer一次,也许在viewDidLoad中。

相关问题