AudioQueueServices playback in background not working

145 views Asked by At

Using AudioQueueServices to play a streaming MP3 file, the player stops when the app is switched to the background.

I have:

  • On the "Background Modes" panel of the "Capabilities" project settings page, I've turned on "Audio, AirPlay and Picture in Picture" and "Background fetch"
  • On the "Info" page, under "Custom iOS Target Properties", added a "Required background modes" node with entries for "App plays audio or streams audio/video using AirPlay" and "App downloads content from the network"

  • In the initialisation code for the player module, I include the following call:

    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &error];

    which completes without signalling an error.

According to my logs, as soon as the app switches to the background, I stop receiving any callbacks, so playback stops almost immediately afterwards. What do I need to do to get it to continue?

1

There are 1 answers

1
selton On
  1. Checking AVAudioSession is active
  2. Checking AudioQueueRef is running:

    UInt32 isRuning = NO;
    UInt32 size = sizeof(isRuning);
    AudioQueueGetProperty(inAQ, kAudioQueueProperty_IsRunning, &isRuning, &size);