AudioToolboxを使用して.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);;
}