开发者

AVAudioSession sound is very low

开发者 https://www.devze.com 2023-03-18 11:03 出处:网络
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.

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

精彩评论

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