Minor Changes
Custom Audio
The 2.10.0 release adds support for custom audio. Audio can be mixed into the existing LocalAudioTrack
by using LocalAudioTrack.setAudioBufferCallback
. This callback will be passed the audio buffer, which can be modified to add in new custom audio (audio processing such as noise/echo cancellation should continue to use the Room.AudioProcessingController
).
To aid in mixing custom audio, a helper class MixerAudioBufferCallback
is provided, which will handle combining the custom audio with the microphone audio. To use, subclass the MixerAudioBufferCallback
and override onBufferRequest
to pass back the custom audio buffers when requested.
Screen Share Audio Capture
Along with the custom audio support, screen share audio capture is supported as well. We've implemented a ScreenAudioCapturer
which will handle grabbing the audio during a screen share session. This can then be passed to LocalAudioTrack.setAudioBufferCallback
to publish the audio.
val audioCapturer = ScreenAudioCapturer.createFromScreenShareTrack(screenCaptureTrack) ?: return
audioCapturer.gain = 0.2f // Adjust the volume as needed so that the microphone can still be heard.
audioTrack.setAudioBufferCallback(audioCapturer)
Foreground service
Note that on Android 14 onwards, a MICROPHONE
foreground service is required to capture audio in the background, which will affect the screen capture audio.
Cleanup
When done with the screen capture, you should call releaseAudioResources
on the capturer to avoid any memory leaks.
Example
Example code that publishes a screenshare with its audio can be found here.