【问题标题】:Why does iOS not inform my application about audio session interruptions?为什么 iOS 不通知我的应用程序有关音频会话中断的信息?
【发布时间】:2012-10-14 18:23:55
【问题描述】:

我正在使用 AVPlayer 播放来自不同来源(包括 iPod 音乐库)的声音。由于 AVPlayer 是更底层的 AVAudioPlayer,我必须自己处理中断。不能使用 AVAudioPlayer!

在 Apple 开发人员文档中,他们提到要么监听 AVAudioSessionInterruptionNotification,要么使用 AudioSessionInitialize 设置监听器。但是这样做时,我只在中断结束时收到通知,但由于their documents,我的应用应该能够同时处理这两个

我正在使用以下代码来初始化我的音频会话:(简化版,删除了不重要的行)

AudioSessionInitialize(NULL, NULL, ARInterruptionListenerCallback, nil);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioSessionSetActive(true);

下面是监听器的样子:

void ARInterruptionListenerCallback(void *inUserData, UInt32 interruptionState) {
    if (interruptionState == kAudioSessionBeginInterruption) {
        // Here is the code which is never called...
    }
    else if (interruptionState == kAudioSessionEndInterruption) {
        // But this case will be executed!
    }
}

顺便说一句。我期待当有电话或类似的中断时执行此代码。我是否误解了 Apple 声明的中断?

【问题讨论】:

  • 嘿,@miho 我也有同样的问题。当我接到电话和 siri 中断工作正常时开始和结束。但是当我打开 iPod 音乐库并播放一些音乐文件时,会调用中断开始,但从不调用中断结束。请任何人对此有解决方案。请发帖所以我一定会放弃一个upWot。

标签: objective-c ios avaudiosession


【解决方案1】:

iOS 6 中存在一个错误。似乎从未为开始中断调用中断代码 - 这包括旧的弃用方法(使用 AVAudioSession 委托)和新的通知方法。

我自己和其他一些人已经向 Apple 提出了一个高度严重的错误请求,所以我建议你也这样做 (bugreport.apple.com) 以引起他们的注意。

我不确定您使用中断的目的是什么,但我正在使用它来允许音频在必要时在中断后恢复,并更新界面中的播放/暂停按钮。我不得不改变我的方法来观看 AVPlayer 速率属性来切换播放/暂停按钮,并且不允许音频在中断后恢复。

编辑:this thread

【讨论】:

  • 感谢您的回复。我也创造了一个这样的工作。我打算把这个问题报告到现在。
猜你喜欢
  • 2020-05-10
  • 1970-01-01
  • 1970-01-01
  • 2020-07-31
  • 2011-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多