I have a test application set to run in the background. It calls deviceManager.closeAudioDevice() when interruptions are detected, and when a routing change is detected. A user action can then resume the running state calling deviceManager.restartLastAudioDevice();
This works great for everything (call interruptions, playing the music player, removing headphones) . . apart from Siri. When Siri interrupts playback, the device is closed, but when restartLastAudioDevice() is called by some user action, the buffersize has doubled relative to before the interruption. Eh?
I should probably add that I have the plist set so that audio runs in the background. It is also necessary to make some subtle mods to the iOS audio class . . .
-
Added some safety code to catch if the user disables all input and outputs. Otherwise, setsize hits an assertion that causes stuff to fail.
void prepareFloatBuffers()
{
if(!(numInputChannels+numOutputChannels)) return; //Edit
floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
-
I close the device manager when a device becomes unavailable. It is important to return from the function here so that it doesn’t try to start itself up again.
if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
{
const ScopedLock sl (callbackLock);
if (callback != nullptr) {
callback->audioDeviceError ("Old device unavailable");
return; //: Need to return here else the rest of the routing function will restart the device. FAIL!
}
}
- Need to comment all the start / restart code from the interruption handling. Again, I do this manually with devicemanager closing and restarting in the error callback.
void interruptionListener (const UInt32 interruptionType)
{
if (interruptionType == kAudioSessionBeginInterruption)
{
// : Need to comment this out when app can run in background
// isRunning = false;
// AudioOutputUnitStop (audioUnit);
// AudioSessionSetActive (false);
const ScopedLock sl (callbackLock);
if (callback != nullptr)
callback->audioDeviceError ("iOS audio session interruption");
}
if (interruptionType == kAudioSessionEndInterruption)
{
// : Need to comment this out when app can run in background
// isRunning = true;
// AudioSessionSetActive (true);
// AudioOutputUnitStart (audioUnit);
}
}
-
I allow iOS to do it’s default thing here. I don’t want the output to default to the speaker!!
I am, similarly, closing the audio device when Siri interrupts us. You can see my post here... http://www.juce.com/forum/topic/siri-interruption-makes-my-audio-distorted
I cannot see why the audio is coming back so distorted.