【问题标题】:Handling interruptions with Audio queue使用音频队列处理中断
【发布时间】:2009-03-23 13:35:34
【问题描述】:

我正在开发一个音频流媒体,并声明了一个中断侦听器,以在发生中断时保存歌曲的状态 - 例如来电或短信。

这里是相关代码

在我的 AppDelegate 中,我有这个

AudioSessionInitialize (NULL, NULL, interruptionListenerCallback, self);
AudioSessionSetActive(YES);

这就是中断监听器的样子

void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) {
// This callback, being outside the implementation block, needs a reference 
//to the AudioPlayer object
MyPlayer *player = (MyPlayer *)inUserData;

if (interruptionState == kAudioSessionBeginInterruption) {
    if ([player audioStreamer]) {
        // if currently playing, pause
        [player pausePlayback];
        player.interruptedOnPlayback = YES;
    }

} else if ((interruptionState == kAudioSessionEndInterruption) && player.interruptedOnPlayback) {
    // if the interruption was removed, and the app had been playing, resume playback
    [player resumePlayback];
    player.interruptedOnPlayback = NO;
}

}

当我接到电话时,会调用中断侦听器,如果用户拒绝通话,还会调用播放恢复方法。但是在调用 resumePlayback 方法之前,我在控制台中为 AudioQueueEnqueueBuffer 收到此错误

错误:tca! 错误整数:560030580

有没有人知道如何在流式传输音频文件时正确处理音频中断。

谢谢。

【问题讨论】:

    标签: iphone audio streaming


    【解决方案1】:

    此链接显示问题所在。可能会帮助某人。

    https://devforums.apple.com/message/31758#31758

    【讨论】:

      【解决方案2】:

      !act 是 kAudioSessionNotActiveError,在 AudioServices.h 中声明,带有注释

      “操作失败,因为 AudioSession 未激活。在大多数情况下,首先调用 AudioSessionSetActive(true) 将修复此错误。”

      在中断后调用 AudioQueueStart() 时也会出现此错误(正如我今天发现的那样)。

      【讨论】:

      • 在我的情况下,这是因为我在暂停播放 AVPlayer 之前停止了会话。
      【解决方案3】:

      在我看来,您将 inUserData 设置为您的 appDelegate 而不是您的播放器。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多