AVAudioSessionDelegate在endInterruption处调用,但未调用beginInterruption [英] AVAudioSessionDelegate called at endInterruption, but beginInterruption not called

查看:281
本文介绍了AVAudioSessionDelegate在endInterruption处调用,但未调用beginInterruption的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用启动并将代理设置为appDelegate时,我正在设置AVAudioSession。一切似乎都在工作(播放等),除了在电话接到电话时没有调用委托上的beginInterruption。当呼叫结束时,正在调用endInterruption。

I'm setting up an AVAudioSession when the app launches and setting the delegate to the appDelegate. Everything seems to be working (playback, etc) except that beginInterruption on the delegate is not being called when the phone receives a call. When the call ends endInterruption is being called though.

我唯一想到的是我以前使用的音频播放器代码基于AVAudioPlayer,但现在使用AVPlayer。用于处理中断的AVAudioPlayer委托的回调仍在那里,但它们会以任何方式发生冲突似乎很奇怪。

The only thought I have is that the audio player code I'm using used to be based on AVAudioPlayer, but is now using AVPlayer. The callbacks for the AVAudioPlayer delegate for handling interrupts are still in there, but it seems odd that they would conflict in any way.

推荐答案

查看标题,在iOS6中,看起来AVAudioSessionDelegate现已弃用。

Looking at the header, in iOS6, it looks like AVAudioSessionDelegate is now deprecated.

在iOS6中使用 AVAudioSessionInterruptionNotification

更新:那没用。我认为框架中存在一个错误。

Update: That didn't work. I think there's a bug in the framework.

是的,根据我的经验,beginInterruption,以及新记录的AVAudioSessionInterruptionNotification正常工作。我要做的是使用本地标志跟踪播放器的状态,然后处理 endInterruption:withFlags:方法,以便跟踪中断恢复。

Yes, in my experience, beginInterruption, nor the newly documented AVAudioSessionInterruptionNotification work properly. What I had to do was track the status of the player using a local flag, then handle the endInterruption:withFlags: method in order to track recovery from interruptions.

对于iOS 6,从中断恢复将至少使您的AudioPlayer保持在正确的位置,因此我无需存储上次已知的播放时间我的AVAudioPlayer,我只是不得不打。

With iOS 6, the resuming from an interruption will at least keep your AudioPlayer in the right place, so there was no need for me to store the last known play time of my AVAudioPlayer, I simply had to hit play.

这是我提出的解决方案。如果AVPlayer驻留时间过长,iOS 6似乎会通过媒体重置来杀死您的音频。最终发生的是AVPlayer播放,但没有声音出来。 AVPlayer的速率是1,但绝对没有声音。为了增加这种情况的痛苦,AVAudioSession setActive和AVPlayer本身都没有错误,表明存在问题。

Here's the solution that I came up with. It seems like iOS 6 kills your audio with a Media Reset if an AVPlayer stays resident too long. What ends up happening, is the AVPlayer plays, but no sound comes out. The rate on the AVPlayer is 1, but there's absolutely no sound. To add pain to the situation, there's no error on either the AVAudioSession setActive, nor the AVPlayer itself that indicates that there's a problem.

此外,您不能依赖appWillResignActive,因为如果您依赖远程控制手势,您的应用可能已经在后台。

Add to the fact that you can't depend on appWillResignActive, because your app may already be in the background if you're depending on remote control gestures at all.

我实现的最终解决方案是在AVPlayer上添加一个定期观察者,并记录上次已知的时间。当我收到我已经获得控制权的事件时,我创建了一个新的AVPlayer,使用AVPlayerItem加载它,并将seekToTime加载到适当的时间。

The final solution I implemented was to add a periodic observer on the AVPlayer, and record the last known time. When I receive the event that I've been given back control, I create a new AVPlayer, load it with the AVPlayerItem, and seekToTime to the proper time.

这是一个非常烦人的解决方法,但至少它可行,并避免发生的周期性崩溃。

It's quite an annoying workaround, but at least it works, and avoids the periodic crashes that were happening.

这篇关于AVAudioSessionDelegate在endInterruption处调用,但未调用beginInterruption的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆