Playing audio in background shows red flashing status bar

Hi,

Probably the audio session setup in juce_ios_Audio.cpp is indicating recording which will make the status bar flash red and showing recording.

For testing I changed line 125 in juce_ios_Audio.cpp from

    UInt32 audioCategory = audioInputIsAvailable ? kAudioSessionCategory_PlayAndRecord
                                                 : kAudioSessionCategory_MediaPlayback;

to

    UInt32 audioCategory = kAudioSessionCategory_MediaPlayback;

That silenced audio in my app on the device completely. So it is not that easy to fix.

I initialize my AudioDeviceManager like this:

	m_audioDeviceManager->initialise(0, AudioProperties::NumberOfOutputChannels, NULL, true);

I think the red status bar should only appear if I request input channels, not when I only request output channel as in the line above.

Any ideas how to get rid of that annoying flashing thing?

Patrick

My app shows that red bar every time I close it. It has nothing to do with the fact that you’re running audio I believe. That’s iOS simply saying that it’s recording the state of your application so that it can quick launch it if the user reopens it.

That’s iOS simply saying that it’s recording the state of your application so that it can quick launch it if the user reopens it.

I don’t think so. A red flashing status bar would be a bit overkill to indicate that the apps state is stored.

The reason you are seeing it only when your app closes is that this is the only time your app goes briefly into background mode before it is stopped by the operating system.

To reproduce the effect try the following:

If you have an audio playing app add into your App’s plist the “Required background modes” (UIBackgroundModes) key with a value of “App plays audio” (audio). Then open your app and play some audio. Switch away from your app by going back to the launch screen of your iOS device. It should continue playing audio and it will show the red flashing status bar.

Patrick

If you’re sure it’s because you’re playing audio, can’t you just stop your audio device when the app is told to quit?

It’s not quit. It goes into the background (Multi-Tasking) but keeps playing audio. This is how it should work. The app goes into background but keeps playing audio. I don’t want the audio to stop.

The problem seems to be that iOS thinks my app is recording. But I am only playing audio.

Ah, I see…

Does it go away if you hack the audioInputIsAvailable value in the iOS audio code, so that it’s always false?

No but it goes away if I dont call initialize on the AudioDeviceManager.

Ok, well I don’t know then… If you hack out that variable, it certainly won’t open any kind of input device, so I don’t think the OS would think that it’s recording.

Here is the fix.

Commenting line 481 in juce_ios_Audio.cpp removed the red status bar while audio keeps playing:

    // AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));

Can this somehow integrated into the code? audioInputIsAvailable should probably used here as well. Furthermore the number of requested input channels when initializing the audio manager should have influence as well?

Ah, interesting, thanks! It’s probably no more complicated than this:

if (numInputChannels > 0) { const UInt32 one = 1; AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one)); }