Using audio input causes app to crash when HOME button is pressed

Hi, I found out when I setup ofSoundStream with non-zero numInputChannels, it causes my app to crash as soon as HOME button on the Android device is pressed.

ofSoundStreamSetup(numOutputChannels, numInputChannels, this, sampleRate, bufferSize, nBuffers);

If I set numInputChannels value to 0, then it no longer has the problem.
And when I print ofSoundStream::getNumInputChannels(), then it prints 1 as it should be.

But I don’t understand why it causes the problem if I setup ofSoundStream with numInputChnnels set to 1.

The problem occurred on both emulators and real device.
And I tested this on emptyExample without using any other addons.

If you already have a working android project, you can easily test this behaviour by writing this single line of code in ofApp::setup();

ofSoundStreamSetup(2, 1, this, 44100, 256, 3);

And if you press HOME button while app is running, the app will crash.
If you change the second argument to 0 and do the same, the app won’t crash.

Can pressing HOME button affect audio input stream?
I would appreciate any suggestion to fix it.
Thanks!

Adding the following permission on AndroidManifest.xml fixed the issue.

<uses-permission android:name="android.permission.RECORD_AUDIO" />

1 Like