嘿,伙计们,我要切入我想要播放的声音
- (IBAction)click1:(id)sender{
Drill.image = [UIImage imageNamed:@"Drillx2"];
AudioServicesPlaySystemSound(PlaySoundID);
}
- (IBAction)click2:(id)sender
{
Drill.image = [UIImage imageNamed:@"Drillx1"];
}
- (void)viewDidLoad {
NSURL *SoundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Drill" ofType:@"m4a"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)SoundURL, &PlaySoundID);
[super viewDidLoad];
}我得到了这个错误
‘'NSInvalidArgumentException',原因:’* -NSURL initFileURLWithPath::nil字符串参数‘
谢谢,德里克
注意:是的声音的资源被命名为。
发布于 2016-03-02 03:10:26
在代码中
NSURL *SoundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Drill" ofType:@"m4a"]];它没有在包文件路径中找到给定的文件。
确保在适当的目标中添加了文件,并在添加资源后再次构建,以确保它存在于包中。
参考文献:编写在参数Passing nil for this parameter produces an exception.中
https://stackoverflow.com/questions/35737633
复制相似问题