Hi there,
I’m currently using the 8.0.8 release on Android, and I found a bug in juce_Oboe_android.cpp that causes audio input to break when plugging or unplugging wired earbuds while the app is running.
Steps to reproduce:
- Create a blank GUI project for Android using Projucer.
- Create a
juce::AudioIODeviceCallbackto be used withjuce::AudioDeviceManager - Initialize
juce::AudioDeviceManagerwith 1 input channel and 2 output channelsaudioDeviceManager.initialiseWithDefaultDevices(1, 2); - Run the app and confirm the audio loop is working.
- Plug in or unplug a pair of wired earbuds.
At this point, the input stream would stop receiving new data while the output continues to work. (The issue only occurs with wired earbuds, since Bluetooth handles input audio differently.)
I did some digging. It looks like JUCE doesn’t handle Oboe’s onErrorAfterClose callback correctly.
In juce_Oboe_android.cpp at line 954 ( JUCE/modules/juce_audio_devices/native/juce_Oboe_android.cpp at d6181bde38d858c283c3b7bf699ce6340c050b5d · juce-framework/JUCE · GitHub ), when JUCE receives oboe::Result::ErrorDisconnected, it should reset both the input and output streams. Right now it only resets the output stream. (To learn more, checkout this Oboe sample code: https://github.com/google/oboe/blob/main/samples/LiveEffect/src/main/cpp/LiveEffectEngine.cpp.)
Adding the following block after line 980 seems to fix the issue. However, I have not dug deeply enough into JUCE’s internals to be certain this will not cause other problems, so please give it a second look.
if (inputStream != nullptr) {
inputStream.reset(new OboeStream(inputDeviceId,
oboe::Direction::Input,
oboe::SharingMode::Exclusive,
numInputChannels,
streamFormat,
sampleRate,
bufferSize,
nullptr));
inputStream->start();
}
