2009-08-07 85 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中。

相關問題