开发者

AVAudioSession sound is very low

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜