Retaining microphone access in the background using Video API Android SDK Retaining microphone access in the background using Video API Android SDK

Retaining microphone access in the background using Video API Android SDK

Paul Bird

Symptom

Apps developed using Video API native android SDK are only able to access the microphone in the background for 60 seconds. After 60 seconds, the publisher's audio automatically stops for the android user.

Applies To

  • Video API Android SDK

Resolution

As per official android developer docs: https://developer.android.com/guide/topics/media/sharing-audio-input#pre-behavior

"One more change was added in Android 9: only apps running in the foreground (or a foreground service) could capture the audio input. When an app without a foreground service or foreground UI component started to capture, the app continued running but received silence, even if it was the only app capturing audio at the time."

So, when you are using Video API Android SDK, the application developer should launch the foreground service that requests microphone access as below:

<service android:name=".MyForegroundService" android:foregroundServiceType="microphone" />

Make sure you start the service as the app goes in the background and stop the service as the app comes into the foreground or as per your use-case requirement.

Additional Information

Please visit here: https://github.com/dharamvirsaini/BGMicrophoneAccess_Vonage_Video to download the complete source code.