Skip to main content
Version: 0.x.x

Manage Audio and Video Devices - Android

This feature allows hosts to switch their microphone, speaker, or camera devices during a live stream. Only hosts (in SEND_AND_RECV mode) can change input/output devices, ensuring they maintain control over their audio and video quality, while audience members (in RECV_ONLY mode) continue to receive the broadcast seamlessly.

Changing Input/Output Audio Device​

getMics()​
  • This method of the Meeting class provides a list of all available microphones, which can be shown in a dropdown for selection.

  • It returns an array of objects, each containing a deviceId and a label representing an audio input device.

changeMic()​
  • Participant can change the audio device using changeMic(AppRTCAudioManager.AudioDevice device) method of Meeting class.

  • Parameters that can be passed to changeMic are

    Audio DevicesUsage
    AppRTCAudioManager.AudioDevice.BLUETOOTHFor Bluetooth Device.
    AppRTCAudioManager.AudioDevice.WIRED_HEADSETFor Wired Handset Device.
    AppRTCAudioManager.AudioDevice.SPEAKER_PHONEFor Inbuilt - Speaker Device
    AppRTCAudioManager.AudioDevice.EARPIECEFor Earpiece Device
  • When participant changes the Mic, AppRTCAudioManager.AudioManagerEvents() is triggered which can be set to Meeting class by using setAudioDeviceChangeListener().

Example​

private fun getMics(): MutableSet<AppRTCAudioManager.AudioDevice>? {
val mics = liveStream!!.mics
return mics // returns all connected mics
}

btnChangeMic!!.setOnClickListener { _: View? ->
// Change Mic during Meeting
liveStream!!.changeMic(AppRTCAudioManager.AudioDevice.BLUETOOTH)
}

private fun setAudioDeviceListeners() {
liveStream!!.setAudioDeviceChangeListener(object : AudioManagerEvents {
override fun onAudioDeviceChanged(
selectedAudioDevice: AppRTCAudioManager.AudioDevice,
availableAudioDevices: Set<AppRTCAudioManager.AudioDevice>
) {
when (selectedAudioDevice) {
AppRTCAudioManager.AudioDevice.BLUETOOTH ->
Toast.makeText(this@MainActivity, "Selected AudioDevice: BLUETOOTH", Toast.LENGTH_SHORT).show()

AppRTCAudioManager.AudioDevice.WIRED_HEADSET ->
Toast.makeText(this@MainActivity, "Selected AudioDevice: WIRED_HEADSET", Toast.LENGTH_SHORT).show()

AppRTCAudioManager.AudioDevice.SPEAKER_PHONE ->
Toast.makeText(this@MainActivity, "Selected AudioDevice: SPEAKER_PHONE", Toast.LENGTH_SHORT).show()

AppRTCAudioManager.AudioDevice.EARPIECE ->
Toast.makeText(this@MainActivity, "Selected AudioDevice: EARPIECE", Toast.LENGTH_SHORT).show()
}
}
})
}

override fun onCreate(savedInstanceState: Bundle?) {
// ...
setAudioDeviceListeners()
}
  • To use Bluetooth device, you must declare BLUETOOTH permission in AndroidManifest.xml file.
<manifest ... >
//...
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
</manifest>

Changing Camera Input Device​

changeWebcam()​
  • To change the camera device of the host, you need to call changeWebcam() method.

Example​

  btnWebcam!!.setOnClickListener {
// Change Webcam during liveStream
liveStream!!.changeWebcam()
}

API Reference​

The API references for all the methods and events utilised in this guide are provided below.

Got a Question? Ask us on discord