Skip to main content
Version: 0.1.x

Mic Controls - Android

Whenever any participant wants to start / stop broadcasting their audio to other participant in meeting, they can simply do it with VideoSDK Meeting.

This guide will provide an overview of how to use enable and disable Mic in a meeting.

  1. Enable Mic - By using unmuteMic() function, a participant can publish audio to other participants.
  2. Disable Mic - By using muteMic() function, a participant can stop publishing audio to other participants.

1. Enable, Disable Mic

  private var micEnabled = false

btnMic!!.setOnClickListener { _: View? ->
// Toggle participant mic in meeting
if (micEnabled) {
meeting!!.muteMic()
micEnabled=false
} else {
meeting!!.unmuteMic()
micEnabled=true
}
}

Events

Event associated with unmuteMic():

Event associated with muteMic():

  meeting!!.localParticipant.addEventListener(object : ParticipantEventListener() {
override fun onStreamEnabled(stream: Stream) {
//
if(stream.getKind().equals("audio")){
//participant turned on audio
}
}

override fun onStreamDisabled(stream: Stream) {
//
if(stream.getKind().equals("audio")){
//participant turned off audio
}
}
});

2. Change Audio Device

Get all audio Devices

  • By using meeting.getMics() function, a participant can get all the connected mics.
  private fun getMics(): MutableSet<AppRTCAudioManager.AudioDevice>? {
val mics= meeting!!.mics
return mics // returns all mics
}

Select audio Device

  • Local 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 a Local participant changes the Mic, AppRTCAudioManager.AudioManagerEvents() is triggered which can be set to Meeting class by using meeting.setAudioDeviceChangeListener()


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

private fun setAudioDeviceListeners() {
meeting!!.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 ... >

<!-- Needed to communicate with already-paired Bluetooth devices. (Legacy up to Android 11) -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
//...
</manifest>

Got a Question? Ask us on discord