For some reason when i play a sound in my app i can barely hear it. ANy idea why? Below is the code i use to play a sound.
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,s开发者_C百科izeof (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];
You need to call AVAudioSession.sharedInstance().setActive(true)
I moved AudioSession init from viewDidLoad to viewDidAppear and the sound is not low anymore. Hope this help.
精彩评论