diff --git a/modules/juce_audio_devices/native/juce_ios_Audio.cpp b/modules/juce_audio_devices/native/juce_ios_Audio.cpp index fb560b57c2..0ba4aa6ff4 100644 --- a/modules/juce_audio_devices/native/juce_ios_Audio.cpp +++ b/modules/juce_audio_devices/native/juce_ios_Audio.cpp @@ -34,16 +34,18 @@ public: callback (nullptr), floatData (1, 2) { + getSessionHolder().activeDevices.add (this); + numInputChannels = 2; numOutputChannels = 2; preferredBufferSize = 0; - AudioSessionInitialize (0, 0, interruptionListenerStatic, this); updateDeviceInfo(); } ~IPhoneAudioIODevice() { + getSessionHolder().activeDevices.removeValue (this); close(); } @@ -336,6 +338,31 @@ private: } } + //================================================================================================== + struct AudioSessionHolder + { + AudioSessionHolder() + { + AudioSessionInitialize (0, 0, interruptionListenerCallback, this); + } + + static void interruptionListenerCallback (void* client, UInt32 interruptionType) + { + const Array & activeDevices = static_cast (client)->activeDevices; + + for (int i = activeDevices.size(); --i >= 0;) + activeDevices.getUnchecked(i)->interruptionListener (interruptionType); + } + + Array activeDevices; + }; + + static AudioSessionHolder& getSessionHolder() + { + static AudioSessionHolder audioSessionHolder; + return audioSessionHolder; + } + void interruptionListener (const UInt32 interruptionType) { /*if (interruptionType == kAudioSessionBeginInterruption) @@ -373,11 +400,6 @@ private: static_cast (client)->routingChanged (propertyValue); } - static void interruptionListenerStatic (void* client, UInt32 interruptionType) - { - static_cast (client)->interruptionListener (interruptionType); - } - //================================================================================================== void resetFormat (const int numChannels) noexcept {