0

我正在创建一个应用程序,在我的应用程序中我正在更改倒计时的图像。我想在一秒完成时播放滴答声(我的意思是当图像更改时)。我有一个 25 秒长的声音,带有重复的滴答声并且在时间间隔内1 秒。有时它工作正常,但有时它不是。现在我如何与我的计时器同步音频。感谢任何帮助。

4

2 回答 2

0

我建议将 AudioServicesCreateSystemSoundID 与只有一个滴答声的声音文件一起使用,大约为 1/16 秒或更短,并在您的 init 中使用它:

clickSound = [[self createSoundWithName:@"click"] intValue];

这是设置声音的代码:

- (NSNumber*) createSoundWithName: (NSString*) name {
SystemSoundID soundID = -1;

NSString *path =[[NSBundle mainBundle] pathForResource:name ofType:@"caf"];
if (path != nil) {
    NSURL *url = [NSURL fileURLWithPath:path];
    if (url != nil) {
        OSStatus err = AudioServicesCreateSystemSoundID ((CFURLRef) url, &soundID);
        if (err) NSLog (@"AudioServicesCreateSystemSoundID error %d", err);
    }
}
return [NSNumber numberWithInt:soundID];
}

这是您播放点击的地方:

- (void) playClick  {
AudioServicesPlaySystemSound (clickSound);
}
于 2009-12-31T17:36:03.063 回答
0

记录 25 个滴答声?)为什么不使用一个滴答声记录?如果响度不是您的目标,您可以播放它,AudioServicesCreateSystemSoundID然后每秒调用AudioServicesPlaySystemSound一次。

于 2009-11-25T08:55:29.877 回答