中断后,录音时延迟音频路线变更通知

发布于 2024-08-19 19:54:22 字数 564 浏览 8 评论 0原文

我的 iPhone 应用程序要求我知道用户何时插入/未插入耳机。这很容易。 AudioSessionAddPropertyListener 具有监听 kAudioSessionProperty_AudioRouteChange 的回调。

当事情发生时我用 NSLog 写日志。用户插入耳机了吗?获取通知以及 gdb 控制台中的一行。用户拔掉耳机?同上。

同时,我通过启动录音音频队列来感知环境的噪音水平。这也很有效:我可以很好地获取麦克风噪音水平并聆听音频路线的变化。

我发现,在中断之后,我重新激活了音频会话并将音频类别恢复为 kAudioSessionCategory_RecordAudio,音频路由通知变得有点混乱。

当我插入耳机时,我没有看到任何通知。当我拔下耳机时,我会快速连续地看到“已插入”通知和“已拔出”通知。

这就像“插入”通知被延迟,当“拔出”通知到达时,待处理通知队列被刷新。

我做错了什么?如何正确恢复音频会话以获得及时通知?

编辑:iPhone OS 3.1.2,在 iPhone 3G 上运行。我正在运行一个用 3.0 SDK 编译的程序(来自 XCode 3.1.2)。

My iPhone application requires that I know when a user has/has not plugged in her headphones. That's easy. AudioSessionAddPropertyListener with a callback listening to kAudioSessionProperty_AudioRouteChange.

I write logs with NSLog as things happen. User plugs the headphones in? Get a notification, and a line in the gdb console. User unplugs the headphones? Ditto.

At the same time I'm sensing the noise level of the environment by starting a recording audio queue. This, too, works great: I can get the mic noise level and listen for audio route changes just fine.

What I find is that after an interruption, and I've reactivated the audio session and restored the audio category to kAudioSessionCategory_RecordAudio, the audio route notifications go a bit haywire.

When I plug in the headphones, I see no notification. When I unplug the headphones I see BOTH the "plugged in" notification AND the "unplugged" notification, in rapid succession.

It's like the "plugged in" notification's delayed and, when the "unplugged" notification arrives, the queue of pending notifications is flushed.

What am I doing wrong? How do I correctly restore the audio session to get timeous notifications?

EDIT: iPhone OS 3.1.2, running on an iPhone 3G. I'm running a program compiled with the 3.0 SDK (from within XCode 3.1.2).

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

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

发布评论

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

评论(1

淡墨 2024-08-26 19:54:22

我有同样的问题,但有更多信息,因此向您提出问题。
您是否像我一样使用 OpenAL 来获得声音?
你也和我一样支持iPod音乐吗?
我在石英菜单屏幕中耳机断开连接很好,但在 glView 游戏屏幕中它大多像你一样失败。有时,第一次断开连接有效,然后失败。有时重新连接也无法触发,因此当我切换到石英屏幕时,我会收到六个必须单击的断开连接对话框。这是 OpenAL 声音。
对于 iPod 音乐,我切换到 NSNotificationCenter MPMusicPlayerControllerPlaybackStateDidChangeNotification 通知,并且该通知有效,但仅在 iPod 音乐播放时有效。
iPhone 和 iTouch 上的 OS 3.1.3 构建为 OS 3.1.0。
看看 AudioSessionInitialize() 的返回错误代码,这是我的问题,它没有被首先调用,并且失败了。
编辑:修复失败,这是一个间歇性/随机问题,似乎是由高 CPU 负载引起的。

I have the same problem, but more information, and thus questions for you.
Are you using OpenAL for sound like me.
Do you also support iPod music like me.
I get headphone disconnects in quartz menu screens fine, but in the glView game screen it mostly fails like you. Sometimes the first disconnect works, then failure. Sometime the reconnect also fails to fire, so when I switch to quartz screen I get a que of a half dozen disconnect dialogs I have to click on. This is with OpenAL sound.
With iPod music I switch to a NSNotificationCenter MPMusicPlayerControllerPlaybackStateDidChangeNotification notification and that works, but only while the iPod music is playing.
OS 3.1.3 with a build to OS 3.1.0 on iPhone and iTouch.
Look at your return error code from AudioSessionInitialize(), that was my problem, it was not being called first, and failed.
EDIT: Fix failed, it is an intermittent/random issue, seemingly caused by high CPU load.

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