AVAudioPlayer 在 iPhone 上非常安静,但在 iPod touch 上声音足够大

发布于 2024-10-04 11:05:39 字数 566 浏览 0 评论 0原文

当使用 AVAudioRecorder 注册噪音时,我有一些循环播放的声音。

这是我的代码:

NSString *pathToFile = [[NSBundle mainBundle] pathForResource:@"foghornRepeat2" ofType:@"aif"];
        foghornRepeat =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathToFile] error:nil];
        //foghornRepeat.delegate = self;
        [foghornRepeat prepareToPlay];

        foghornRepeat.numberOfLoops = -1;
        [foghornRepeat setVolume:1];

然后当通过麦克风注册声音时播放和停止。知道为什么 iPhone 上会非常安静吗?在我的 iPod touch 上没问题。

我还有其他方法可以做到这一点吗?

谢谢 汤姆

I have some sound that is played in a loop as a noise is registered using an AVAudioRecorder.

Here is my code:

NSString *pathToFile = [[NSBundle mainBundle] pathForResource:@"foghornRepeat2" ofType:@"aif"];
        foghornRepeat =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathToFile] error:nil];
        //foghornRepeat.delegate = self;
        [foghornRepeat prepareToPlay];

        foghornRepeat.numberOfLoops = -1;
        [foghornRepeat setVolume:1];

It is then played and stopped when sound is registered through the microphone. Any idea why this would be really quiet on an iphone? Its fine on my ipod touch.

Is there any other way I can do this?

Thanks
Tom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷遇一生 2024-10-11 11:05:39

可能发生的情况是 iPhone 上的音频重新路由到手机扬声器。为了确保声音从真实的扬声器中播放,请在播放音效之前使用以下代码:

   UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
 AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

What probably happened is that the audio on your iphone rerouted to the phone speakers. To make sure the sound plays from the real speakers, use the following code before you play a sound effect:

   UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
 AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文