出于某种原因,当我在我的应用程序中播放声音时,我几乎听不到它。知道为什么吗?下面是我用来播放声音的代码。
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
NSString *audioFilePath = [[NSBundle mainBundle] pathForResource:soundToPlay ofType:@"wav"];
NSURL *audioFileURL = [NSURL fileURLWithPath:audioFilePath];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:nil];
audioPlayer.volume = 1;
[audioPlayer prepareToPlay];
[audioPlayer play];