我正在使用Xcode创建Mac OSX, Objective-C, cocoa app.
我想让我的应用在一段时间后播放自定义声音。
这就是我的代码:
- (IBAction)clickToPlayCustomSoundButtonClicked {
[self performSelector:@selector(playCustomSound) withObject:nil afterDelay:1.0];
}
- (void)playCustomSound {
***This is where I want to put the code to play the custom sound***
}
我应该在(void)playCustomSound
方法中使用哪些代码来播放自定义声音?
请帮助并谢谢你们:D
答案 0 :(得分:0)
试试这个(假设你的声音文件在你的Ressources文件夹中):
NSSound *player = [[NSSound alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"MyCustomSound" ofType:@"mp3"] byReference:NO];
[player play];