首先对我的英语感到抱歉
我的代码有问题,我尝试做一个声音程序,但在我的代码中出现此错误:
Invalid operands to binary expression ('CFURLRef' (aka 'const struct __CFURL *') and 'CFURLRef')
这是我的完整代码:
- (IBAction)tocar:(id)sender {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundfileURLRef;
soundfileURLRef *CFBundleCopyResourceURL (mainBundle, (CFStringRef) @"Botao", CFSTR ("mp3"), NULL);
UInt32 SoundID;
AudioServicesCreateSystemSoundID(soundfileURLRef, &SoundID);
AudioServicesPlaySystemSound(SoundID);
}
最佳答案
您的CFBundleCopyResourceURL
行弄乱了,等号变成了星号;
soundfileURLRef *CFBundleCopyResourceURL (mainBundle,
(CFStringRef) @"Botao", CFSTR ("mp3"), NULL);
...应该...
soundFileURLRef = CFBundleCopyResourceURL(mainBundle,
(CFStringRef) @"Botao", CFSTR ("mp3"), NULL);