无法在iOS的背景模式中重新启动中断的音频输入队列 [英] Can not restart an interrupted audio input queue in background mode on iOS

查看:183
本文介绍了无法在iOS的背景模式中重新启动中断的音频输入队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AudioQueue编写一个iOS应用程序进行录制。我创建了一个配置为获取线性PCM的输入队列,表示这个队列和一切工作正常。

I'm writing an iOS App using an AudioQueue for recording. I create an input queue configured to get linear PCM, stated this queue and everything works as expected.

为了管理中断,我实现了AVAudioSession的委托方法,和中断的结束。方法endInterruption如下所示:

To manage interruptions, I implemented the delegate methods of AVAudioSession to catch the begin and the end of an interruption. The method endInterruption looks like the following:

- (void)endInterruptionWithFlags:(NSUInteger)flags;
{
    if (flags == AVAudioSessionInterruptionFlags_ShouldResume && audioQueue != 0) {

        NSLog(@"Current audio session - category: '%@' mode: '%@'",
              [[AVAudioSession sharedInstance] category],
              [[AVAudioSession sharedInstance] mode]);

        NSError *error = nil;
        OSStatus errorStatus;
        if ((errorStatus = AudioSessionSetActive(true)) != noErr) {
            error = [self errorForAudioSessionServiceWithOSStatus:errorStatus];
            NSLog(@"Could not reactivate the audio session: %@",
                  [error localizedDescription]);
        } else {
            if ((errorStatus = AudioQueueStart(audioQueue, NULL)) != noErr) {
                error = [self errorForAudioQueueServiceWithOSStatus:errorStatus];
                NSLog(@"Could not restart the audio queue: %@",
                      [error localizedDescription]);
            }
        }
    }
    // ...
}

如果应用程序在前台中断时,一切正常。出现问题,如果中断发生在后台。激活音频会话导致出现错误!cat

If the app gets interrupted while it is in foreground, everything works correct. The problem appears, if the interruption happens in the background. Activating the audio session result in the error !cat:


指定的音频会话类别不能用于尝试的音频操作。例如,您尝试播放或录制音频会话类别设置为kAudioSessionCategory_AudioProcessing的音频。

The specified audio session category cannot be used for the attempted audio operation. For example, you attempted to play or record audio with the audio session category set to kAudioSessionCategory_AudioProcessing.

启动队列而不激活会话结果在错误代码中: -12985

Starting the queue without activating the session results in the error code: -12985

此时,类别设置为 AVAudioSessionCategoryPlayAndRecord ,模式为 AVAudioSessionModeDefault

At that point the category is set to AVAudioSessionCategoryPlayAndRecord and the mode is AVAudioSessionModeDefault.

我找不到此错误消息的任何文档,也无法在后台重新启动输入音频队列。

I couldn't find any documentation for this error message, nor if it is possible to restart an input audio queue in the background.

推荐答案

目前,如果您在后台,则无法重新启动。

At the present there is no way to reactivate if you are in the background.

这篇关于无法在iOS的背景模式中重新启动中断的音频输入队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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