Kotlin

Capturing audio to be used by a publisher

The BaseAudioDevice.startCapturer method is called when the audio device should start capturing audio to be published. The NoiseAudioDevice implementation of this method starts the capturer thread to be run in the queue after 1 second:

override fun startCapturer(): Boolean {
    capturerStarted = true
    capturerHandler?.postDelayed(capturer, capturerIntervalMillis)
    return true
}

The capturer thread produces a buffer containing samples of random data (white noise). It then calls the writeCaptureData method of the AudioBus object, which sends the samples to the audio bus. The publisher in the application uses the samples sent to the audio bus to transmit as audio in the published stream. Then if a capture is still in progress (if the app is publishing), the capturer thread is run again after another second:

private val capturer: Runnable = object : Runnable {
    override fun run() {
        capturerBuffer?.rewind()
        val rand = Random()
        rand.nextBytes(capturerBuffer?.array())
        audioBus.writeCaptureData(capturerBuffer, SAMPLING_RATE)
        if (capturerStarted && !audioDriverPaused) {
            capturerHandler?.postDelayed(this, capturerIntervalMillis)
        }
    }
}

The AudioDevice class includes other methods that are implemented by the NoiseAudioDevice class. However, this sample does not do anything of interest in these methods, so they are not included in this guide.

Custom audio driver

Learn how to use a custom audio driver to customize publisher and subscriber stream audio. You will use the custom audio driver when you want to start and stop the audio play your own audio file, and do anything outside the default behavior of live video chat provided by the SDK.

Available on:
Kotlin Swift
Steps
1
Introduction
2
Getting Started
3
Creating a new project
4
Adding the Android SDK
5
Setting up authentication
6
Requesting permissions
7
Adding a custom audio driver
8
Capturing audio to be used by a publisher
9
Adding a custom audio renderer
10
Running the app
11
Conclusion