ScreenAudioCapturer

@RequiresApi(value = 29)
class ScreenAudioCapturer @RequiresPermission(value = "android.permission.RECORD_AUDIO") constructor(mediaProjection: MediaProjection, captureConfigurator: AudioPlaybackCaptureConfigurator = DEFAULT_CONFIGURATOR) : MixerAudioBufferCallback

A mixer for capturing screen share audio.

Requires a media projection, which can be obtained from the screen share track.

Additionally, for screen capture to work properly while your app is in the background, a foreground service with the type microphone must be running. Otherwise, audio capture will not return any audio data.

Example usage:

Constructors

Link copied to clipboard
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
constructor(mediaProjection: MediaProjection, captureConfigurator: AudioPlaybackCaptureConfigurator = DEFAULT_CONFIGURATOR)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
var gain: Float

A multiplier to adjust the volume of the captured audio data.

Functions

Link copied to clipboard
fun initAudioRecord(audioFormat: Int, channelCount: Int, sampleRate: Int): Boolean
Link copied to clipboard
override fun onBuffer(buffer: ByteBuffer, audioFormat: Int, channelCount: Int, sampleRate: Int, bytesRead: Int, captureTimeNs: Long): Long

Called when new audio samples are ready.

Link copied to clipboard
open override fun onBufferRequest(originalBuffer: ByteBuffer, audioFormat: Int, channelCount: Int, sampleRate: Int, bytesRead: Int, captureTimeNs: Long): MixerAudioBufferCallback.BufferResponse?
Link copied to clipboard

Release any audio resources associated with this capturer. This is not managed by LiveKit, so you must call this function when finished to prevent memory leaks.