AudioQueue callback get empty buffer on iOS 7 only

前端 未结 2 1486
旧巷少年郎
旧巷少年郎 2021-02-04 23:09

I got a strange issue. My code works great on both iOS 5&6 but when running on iOS 7 I get empty buffers on the AudioQueue callback.

Possible relevant code:

相关标签:
2条回答
  • 2021-02-04 23:13

    @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);
    }
    
    0 讨论(0)
  • 2021-02-04 23:37

    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.

    0 讨论(0)
提交回复
热议问题