6

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

这是相关代码

在我的 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

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

谢谢。

4

3 回答 3

3

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

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

于 2009-03-23T14:03:14.230 回答
2

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

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

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

于 2010-01-26T12:59:42.530 回答
0

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

于 2009-03-23T15:22:01.610 回答