オーディオツールボックスと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"];
しかし、音がゼロになります。