我已将音频工具箱和 avfoundation 导入我的班级,并将框架添加到我的项目中,并使用此代码播放声音:
- (void)playSound:(NSString *)name withExtension:(NSString *)extension
{
NSURL* soundUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:name ofType:extension]];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
audioPlayer.delegate = self;
audioPlayer.volume = 1.0;
[audioPlayer play];
}
我这样称呼它:
[self playSound:@"wrong" withExtension:@"wav"];
但是我得到零声音。