出于某种原因,当我在我的应用程序中播放声音时,我几乎听不到它。不知道为什么?下面是我用来播放声音的代码。
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];
答案 0 :(得分:0)
您需要致电AVAudioSession.sharedInstance().setActive(true)
答案 1 :(得分:-1)
我将audioSession init从viewDidLoad移到了viewDidAppear,声音不再低了。希望这有帮助。