首先抱歉我的英文
我的代码有问题,我尝试做一个声音程序但在我的代码中出现此错误:
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);
}
答案 0 :(得分:2)
假设您编写的代码是您实际使用的代码,则此行为奇数:
soundfileURLRef *CFBundleCopyResourceURL (mainBundle, (CFStringRef) @"Botao",
CFSTR ("mp3"), NULL);
asteriks(*
)应该是equlas(=
)
我认为应该是
soundfileURLRef = CFBundleCopyResourceURL (mainBundle, (CFStringRef) @"Botao",
CFSTR ("mp3"), NULL);
答案 1 :(得分:0)
你的CFBundleCopyResourceURL
线被搞砸了,等于变成了星号;
soundfileURLRef *CFBundleCopyResourceURL (mainBundle,
(CFStringRef) @"Botao", CFSTR ("mp3"), NULL);
......应该......
soundFileURLRef = CFBundleCopyResourceURL(mainBundle,
(CFStringRef) @"Botao", CFSTR ("mp3"), NULL);