我正在尝试使用音频工具箱播放 .wav 文件。到目前为止我有这个:但是我的文件不会播放。If 条件被正确触发,但它不播放。如果文件不存在,它将打印错误消息。任何线索有什么问题?
-(void) playSound : (NSString *) fName : (NSString *) ext
{
SystemSoundID audioEffect;
NSString *path = [[NSBundle mainBundle] pathForResource : fName ofType :ext];
if ([[NSFileManager defaultManager] fileExistsAtPath : path])
{
NSURL *pathURL = [NSURL fileURLWithPath : path];
AudioServicesCreateSystemSoundID((__bridge CFURLRef) pathURL, &audioEffect);
AudioServicesPlaySystemSound(audioEffect);
}
else
{
NSLog(@"error, file not found: %@", path);
}
AudioServicesDisposeSystemSoundID(audioEffect);;
}