本文介绍了AVAudioSession中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,在我的应用程序,在iOS 6上运行,一切似乎很好地工作与音频。我用的是旧的C API格式搭上使用回调中断;通过设置: AudioSessionInitialize(NULL,NULL,interruptionListenerCallback,(__bridge无效*)个体经营),这是伟大的。使用的是iOS 7 SDK不过,似乎当设备接收来电或闹钟响起我的中断回调永远不会被调用。

So in my app, running on iOS 6, everything seems to work fine with audio. I use the old C API format to catch interruptions using a callback; setting up via: AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, (__bridge void *)self) and it was great. Using iOS 7 SDK though, it seems that my interruption callback is never called when the device receives calls or an alarm goes off.

一些环顾四周后,我听到了旧的C API一样去precated,您应该移动到新的AVAudioSession功能。更多阅读透露,AVAudioSession委托德precated,您应该使用 NSNotification AVAudioSessionInterruptionNotification 抓中断和做任何需要做的事情。

After some looking around, I heard that the old C api were deprecated and that you should move to the newer AVAudioSession functions. More reading revealed that the AVAudioSession delegate is deprecated and that you should use the NSNotification for AVAudioSessionInterruptionNotification to catch interruptions and do whatever needs to be done.

对于我来说,似乎这个通知实际上从未解雇,所以我从来没有得到正确的中断,然后打破了我所有的东西音频通话结束后。

For me, it seems that this notification is never actually fired and therefore I never get properly interrupted, which then breaks all of my audio stuff after the call ends.

我注册了,像这样的通知:

I sign up for the notification like so:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AudioInterruption:) name:AVAudioSessionInterruptionNotification object:nil];

目前,该 AudioInterruption:功能只需登录其被解雇了。无论是日志也没有任何断点被触发。

For now, the AudioInterruption: function simply logs that it got fired. Neither the log nor any breakpoints are triggering.

需要明确的是,最初的音频播放和录音工作正常。当一个中断发生时(如来电呼叫或报警),无中断通知被激发。如果有更多的周围code是必要的,让我知道。

To be clear, initially audio playback and recording works fine. When an interruption occurs (such as an incoming call or an alarm), no interruption notification is fired. If more surrounding code is necessary, let me know.

推荐答案

你在你的应用程序中有一个的 AVCaptureSession 的实例?结果
如果是这样的话,我会建议我为我的链接的问题得到同样的答案:结果
尝试设置的 NO 的到的 您的 AVCaptureSession 的实例的属性。结果
它是可用的属性,因为iOS的7。在previous的iOS版本,每个版本的 AVCaptureSession 的利用私人的的 AVAudioSession 的。由于iOS的7,捕捉会话利用共享的应用程序的AVAudioSession的。结果
属性是默认启用的,所以如果你想保持原来的行为必须禁止它,通过设置的 NO

Do you have an AVCaptureSession instance in your application?
If that is the case, I would suggest the same answer that I received for my linked question:
Try to set NO to the usesApplicationAudioSession property of your AVCaptureSession instance.
It is a property available since iOS 7. In the previous iOS versions, each AVCaptureSession made use of a private AVAudioSession. Since iOS 7, the Capture Sessions make use of the shared application's AVAudioSession.
The usesApplicationAudioSession property is enabled by default, so if you want to keep the old behavior you must disable it, by setting NO.

我希望这会为你工作,以及。

I hope this will work for you as well.

这篇关于AVAudioSession中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 02:50