Skip to content

Is it possible to open 2 microphones in Android at same time with Oboe library?

I’m trying to open 2 microphone streams with google’s Oboe library like this, for each microphone:

oboe::AudioStreamBuilder builder;
            ->setDirection(isInput ? oboe::Direction::Input : oboe::Direction::Output)
            ->setSharingMode((oboe::SharingMode) sharingMode)
            ->setPerformanceMode((oboe::PerformanceMode) performanceMode)
            ->setSessionId((oboe::SessionId) sessionId)
            ->setFormat((oboe::AudioFormat) format)
            ->setSampleRateConversionQuality((oboe::SampleRateConversionQuality) rateConversionQuality)

oboe::AudioStream *oboeStream = nullptr;
oboe::Result result = builder.openStream(&oboeStream);

As you can see, the deviceId is passed to the builder. This is the microphone ID that I get with some java methods. I pass 7 and 9 as ids, for built-in microphone and telephone microphone. The problem is when I try to start the 2 streams:


I get this error for the second stream:

E/AudioRecord: start() status -38

but if I try to open the first one only, and then the second one only, in 2 different builds, everything works. So is it true that I cannot open 2 microphone streams with Oboe? It looks like a powerful library, it shouldbe possible.



Android doesn’t allow you to capture audio from more than one thread most of the time. It doesn’t matter how many input sources your phone has or which library do you use. You can’t open two audio streams at the same time. Even two separate ordinary applications don’t have access to the input sources simultaneously and if you want to start recording while a stream source captured by another process an error would be returned. From Android 10 some changes occurred. According to the doc:

Android 10 (API level 29) and higher imposes a priority scheme that can switch the input audio stream between apps while they are running. In most cases, if a new app acquires the audio input, the previously capturing app continues to run, but receives silence. In some cases the system can continue to deliver audio to both apps.

Two streams mean two thread which is like two different apps. In some scenarios, two processes can capture audio at the same time like so:

Assistant + ordinary app

Accessibility service + ordinary app

Voice call + ordinary app

For more details please read this page at the Android doc.

User contributions licensed under: CC BY-SA
9 People found this is helpful