Sometimes iOS interrupts the current audio session. This happens for example when another app is put into the foreground that also plays audio.
I also had problems with routing changes when a phone call is coming in.When I accept the phone call audio routing changes from headphone to iPhone speakers while the phone call and audio playback are both still active. This is not optimal
I may be missing something but I see no way to get notified from JUCE about routing changes or audio session interruptions. Therefore there is no way to go to a paused state in my app when that happens.
Any pointers in the right direction would be very much appreciated.
I digged a little deeper for the case were another app is brought to the foreground that also plays audio and iOS interrupts the JUCE audio session.
It seems in this case, in juce_ios_Audio.cpp, the interruptionListener method is only called for kAudioSessionBeginInterruption, never for kAudioSessionEndInterruption.
I may be wrong, but I see no way to reflect this state in the ui or to recover from it without some kind of callback. The AudioDeviceManager also canāt recover from this. Audio is gone for good.
If there was a callback, the app could go into a Stopped or Paused state and show this in the ui. When the user presses play again the AudioDeviceManager could be recreated and audio playback could start again.
Yes, this is all iOS-specific stuff that didnāt fit into the pre-existing audio classes. It does need doing, but itās one of those fiddly tasks thatād probably take me a whole day to research and test, and I donāt have any free days right now. (If anyone wants to contribute some code to do it, that might kick me into action on it, but any new callbacks would need to be designed in a generic, cross-platform way, and not just wrappers around whatever iOS does)
I hacked around the issue for now by misusing the existing audioDeviceError callback. For this I changed the interruptionListener in juce_ios_Audio.cpp:
On a related note, how does the AudioDeviceManager cooperate with samplerate/buffersize changes when the app is re-brought to the foreground after being sent to the background by another app that uses different samplerate/buffersize?
Will it be restored to its previous state? If not, will this change fix the problem?
Given a choice between fixing a show-stopper (audio completely stops) or dramatic improvements to IntroJucer I would pick the one that provides immediate benefits to users instead of developers, but thatās just me.
Given a choice between fixing a show-stopper (audio completely stops) or dramatic improvements to IntroJucer I would pick the one that provides immediate benefits to users instead of developers, but thatās just me.[/quote]
Thanks Vinnie, I already heard you the last 3 or 4 times that you posted this same comment.
Plus, what will happen when you launch a juce app while another app with different samplerate/buffersize is still playing?
I made a simple app that plays just a tone and I set its buffersize to 128 in order to test these issues (I am up-to-date with the tip and I applied the mods from this thread).
It crashes in this last case, but it doesnāt crash in the other cases and it looks like the buffersize is correctly restored.
My comment was not really directed towards you, it was directed towards all the Projucer fanboys who might not realize the full cost of these bells and whistles.
[quote=āmasshackerā]Plus, what will happen when you launch a juce app while another app with different samplerate/buffersize is still playing?
I made a simple app that plays just a tone and I set its buffersize to 128 in order to test these issues (I am up-to-date with the tip and I applied the mods from this thread).
It crashes in this last case, but it doesnāt crash in the other cases and it looks like the buffersize is correctly restored.[/quote]
I made a test with the new code, including the commented out lines. I put on a bluetooth headset and called my iPhone from another phone while my app was running (ah, the joys of mobile device development). udio was interrupted and was faded out nicely by iOS. After I hang up the call my ui showed paused state, I pressed play and audio started again.
Because my bluetooth headset switches to a different samplerate, the code changes fixed the issues I had with interruptions without crashes also with interruptions were samplerates change. Your details may vary of course depending on what your are doing in the device manager callbacks.