How to prevent background audio from stopping when starting a JUCE app?

Hi everyone,

I’m facing an issue where background audio (like YouTube or other apps) stops when I launch my app. How can I configure my app to prevent this from happening? I want the background audio (like YouTube or other synth apps) to continue playing while my JUCE app is running.

I have enabled background playing in the Projuer/Xcode
I tried JUCE_DISABLE_AUDIO_MIXING_WITH_OTHER_APPS=0
But with no luck…

The only I can get it work when I manually set in the Juce sources:

static void setAudioSessionCategory (NSString* category) {
  category = AVAudioSessionCategoryAmbient;
  ....
  ....
}

Thanks in advance for any suggestions!

Hi there, I had the same problem. Changing the JUCE sources seemed to be the easiest solution. In the constructor of iOSAudioIODevice::Pimpl.

I changed
setAudioSessionCategory (AVAudioSessionCategoryPlayAndRecord);
to
setAudioSessionCategory (AVAudioSessionCategoryPlayback);

This should probably be the default, me thinks…

1 Like

Please no, don’t suggest this default be changed.

Professional DAW users require full control over their audio environment - the use-case of enabling Youtube in the background is not appropriate in that situation.

If a professional wants to run audio over a Youtube sound-source, the usual approach is to export the Youtube data and insert it in the DAW as a mixable track.

1 Like

As soon the JUCE app requests audio inputs background audio by other app would stop. That still would be the norm since most apps request audio inputs anyways when starting.

But right now it is not possible to opt out of this and audio by other apps is always interrupted when starting a JUCE app.

It seems there was a misunderstanding. I’m not developing a DAW application, and I don’t use one either. This is a regular GUI program where sound isn’t necessary, though it may handle MIDI messages.

The average user doesn’t require DAW functionality, they need just regular app, but they often ask why the audio stops when the app opens, or why background audio stops when using Command + Tab. This issue is critical for iOS users.

@aamf However, everything works fine when I set AVAudioSessionCategoryAmbient. That’s all we need.

1 Like

If you don’t need Audio capabilities, don’t include it in your app. Or is that not possible?

Well, I certainly need audio capabilities and I think @vtarasuk described the problem clearly.

Reading a bit further into the docs, you can also set a flag without changing it to Ambient:
AVAudioSessionCategoryOptionMixWithOthers

Although looking into the sources that is what JUCE_DISABLE_AUDIO_MIXING_WITH_OTHER_APPS is doing…

@daniel Yeah, I tried that, but with no luck. In general, modifying JUCE source code during app publishing isn’t an issue for me. However, it would be great to have a setting for this through JUCE, either via compilation flags or during setAudioDevice. Unfortunately, I couldn’t find anything similar, and even ChatGPT couldn’t help.