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.
- Enable Mic - By using
unmuteMic()
function, a participant can publish audio to other participants. - Disable Mic - By using
muteMic()
function, a participant can stop publishing audio to other participants.
1. Enable, Disable Mic​
- Kotlin
- Java
private var micEnabled = false
btnMic!!.setOnClickListener { _: View? ->
// Toggle participant mic in meeting
if (micEnabled) {
meeting!!.muteMic()
micEnabled=false
} else {
meeting!!.unmuteMic()
micEnabled=true
}
}
private boolean micEnabled = false;
btnMic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Toggle participant mic in meeting
if (micEnabled) {
meeting.muteMic();
micEnabled = false;
} else {
meeting.unmuteMic();
micEnabled = true;
}
}
});
Events​
Event associated with unmuteMic()
:
- Every Participant will receive a callback on
onStreamEnabled()
of theParticipant
withStream
object.
Event associated with muteMic()
:
- Every Participant will receive a callback on
onStreamDisabled()
of theParticipant
withStream
object.
- Kotlin
- Java
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
}
}
});
participant.addEventListener(new ParticipantEventListener() {
@Override
public void onStreamEnabled(Stream stream) {
//
if(stream.getKind().equals("audio")){
//participant turned on audio
}
}
@Override
public void 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.
- Kotlin
- Java
private fun getMics(): MutableSet<AppRTCAudioManager.AudioDevice>? {
val mics= meeting!!.mics
return mics // returns all mics
}
private Set<AppRTCAudioManager.AudioDevice> getMics() {
Set<AppRTCAudioManager.AudioDevice> mics = meeting.getMics();
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
areAudio Devices Usage AppRTCAudioManager.AudioDevice.BLUETOOTH For Bluetooth Device. AppRTCAudioManager.AudioDevice.WIRED_HEADSET For Wired Handset Device. AppRTCAudioManager.AudioDevice.SPEAKER_PHONE For Inbuilt - Speaker Device AppRTCAudioManager.AudioDevice.EARPIECE For Earpiece Device -
When a Local participant changes the Mic,
AppRTCAudioManager.AudioManagerEvents()
is triggered which can be set toMeeting
class by usingmeeting.setAudioDeviceChangeListener()
- Kotlin
- Java
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()
}
btnChangeMic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Change Mic in Meeting
meeting.changeMic(AppRTCAudioManager.AudioDevice.BLUETOOTH);
}
});
private void setAudioDeviceListeners() {
meeting.setAudioDeviceChangeListener(new AppRTCAudioManager.AudioManagerEvents() {
@Override
public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) {
switch (selectedAudioDevice) {
case BLUETOOTH:
Toast.makeText(MainActivity.this, "Selected AudioDevice: BLUETOOTH", Toast.LENGTH_SHORT).show();
break;
case WIRED_HEADSET:
Toast.makeText(MainActivity.this, "Selected AudioDevice: WIRED_HEADSET", Toast.LENGTH_SHORT).show();
break;
case SPEAKER_PHONE:
Toast.makeText(MainActivity.this, "Selected AudioDevice: SPEAKER_PHONE", Toast.LENGTH_SHORT).show();
break;
case EARPIECE:
Toast.makeText(MainActivity.this, "Selected AudioDevice: EARPIECE", Toast.LENGTH_SHORT).show();
break;
}
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
setAudioDeviceListeners();
}
- To use Bluetooth device, you must declare
BLUETOOTH
permission inAndroidManifest.xml
file.
<manifest ... >
<!-- Needed to communicate with already-paired Bluetooth devices. (Legacy up to Android 11) -->
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<!-- Needed to communicate with already-paired Bluetooth devices. (Android 12 upwards)-->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
//...
</manifest>
Got a Question? Ask us on discord