【问题标题】:I put a button on a table view cell that play sound when they are pressed but我在表格视图单元格上放了一个按钮,当它们被按下时播放声音但是
【发布时间】:2009-08-07 19:30:27
【问题描述】:

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

这是我的代码

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

【问题讨论】:

    标签: iphone button uitableview avaudioplayer


    【解决方案1】:

    我不知道这是否是问题,但您不需要每次都释放并重新分配 AVAudioPlayer。只需停止和启动它就可以正常工作,例如:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      相关资源
      最近更新 更多