我是xcode的新手,我正在尝试创建一个声音应用。在线:theAudio.delegate = self;我收到错误消息:
错误:解析问题:预期';'表达后
以下是代码的副本。
- (IBAction)play:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:@"winning" ofType:@"mp3"];
if(theAudio)[theAudio release];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
非常感谢任何帮助。
答案 0 :(得分:0)
播放后释放音频。
[音频播放]; [theAudio release];
或试试这个
-(void) myPlay: (NSString *) soundFile ofType:(NSString *) ext{
if (ext == nil) {
ext = @"caf";
}
//SystemSoundID soundID;
//create and assign soundID to a particular sound
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:soundFile ofType:ext]] , &soundID);
//AudioServicesPlayAlertSound(soundID);
//To play the sound
AudioServicesPlaySystemSound (soundID);
//Function to allocate a function to be called after the sound(with SoundID) ends(optional)
AudioServicesAddSystemSoundCompletion (soundID,NULL,NULL,soundCompleted,
(void*) self);
}
答案 1 :(得分:0)
我在CoreFoundation.framework
中收到类似的构建错误。
CFURL.h: Expected ';' after top level declarator
CFFileSecurity.h: Expected function body after function declarator
CoreFoundation.h: 'CoreFoundation/CFUserNotification.h' file not found
要修复它们,我删除了我的项目derived data。我是在Projects Organizer,Organizer Window,窗口>下的Xcode中完成此操作的。组织者(Command-Shift-2)。
git clean -dXf
(默认情况下不删除派生数据),这对我来说(因为我忽略xcuserdata
),删除:
MyApp.xcodeproj/project.xcworkspace/xcuserdata/
MyApp.xcodeproj/xcuserdata/
我正要重新格式化我的硬盘并重新安装OS X,现在我看到它也会工作。我很高兴我找到了一个更快,更直接的方法来解决这个问题。