我是 Objective C 的新手,我正在开发一个在 uibutton 的触摸事件上播放声音的应用程序。当我触摸按钮时,它改变的是图像和音频开始播放。音频播放完毕后,我想放置 uibutton 的原始图像。我怎样才能做到这一点?我怎样才能捕捉到音频结束的事件?我正在使用该代码:
- (SystemSoundID) createSoundID: (NSString*)name
{
NSString *path = [NSString stringWithFormat: @"%@/%@",
[[NSBundle mainBundle] resourcePath], name];
NSURL* filePath = [NSURL fileURLWithPath: path isDirectory: NO];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
return soundID;
}
在
viewDidLoad
我打电话
freq = [self createSoundID: @"freq.wav"];
在按钮触摸时调用的函数中,我使用:
AudioServicesPlaySystemSound(freq);
我能怎么做?谢谢!