AVAudioSession声音很低
由于某种原因,当我在应用程序中播放声音时,我几乎听不到它。知道为什么吗?下面是我用来播放声音的代码。
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];
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,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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要调用
AVAudioSession.sharedInstance().setActive(true)
You need to call
AVAudioSession.sharedInstance().setActive(true)
我将 AudioSession init 从 viewDidLoad 移至 viewDidAppear,声音不再低了。希望这有帮助。
I moved AudioSession init from viewDidLoad to viewDidAppear and the sound is not low anymore. Hope this help.