AudioQueue callback get empty buffer on iOS 7 only

纵然是瞬间 提交于 2019-12-03 00:51:30

I found the issue! seems like on iOS 7 there is a need to set this also (I assume this is only practically therefore it's hard to find, isn't written anywhere). Just add this code before calling any AudioQueue function:

AudioSessionInitialize(NULL,
                       NULL,
                       nil,
                       ( void *)(self)
                       );

UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
                        sizeof(sessionCategory),
                        &sessionCategory
                        );

AudioSessionSetActive(true);

Hope that would help others.

Another resource that can help can be found here.

@Idan your answer is correct and working but it only shows warning if app minimun deployment target is iOS 7. For iOS 7 we can do something like this:

NSError *audioSessionError;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&audioSessionError];

if(audioSessionError)
{
    NSLog(@"AVAudioSession error setting category:%@",audioSessionError);
}
else
{
    [audioSession setActive:YES error:&audioSessionError];
    if(audioSessionError)
        NSLog(@"AVAudioSession error activating: %@",audioSessionError);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!