Change Input/Output Device - Android
During the meeting at any point a participant wishes to switch his/her audio or video device, it can be done using the below mentioned methods.
Changing Input/Output Audio Device
getMics()
-
The
getMics()
method will return a list of all available microphones that are connected to the mobile device. -
This method will return a Set of
AppRTCAudioManager.AudioDevice
.
- Kotlin
- Java
private fun getMics(): MutableSet<AppRTCAudioManager.AudioDevice>? {
val mics= meeting!!.mics
return mics // returns all connected mics
}
private Set<AppRTCAudioManager.AudioDevice> getMics() {
Set<AppRTCAudioManager.AudioDevice> mics = meeting.getMics();
return mics; // returns all connected mics
}
changeMic()
-
Participant can change the audio device using
changeMic(AppRTCAudioManager.AudioDevice device)
method ofMeeting
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 participant changes the Mic,
AppRTCAudioManager.AudioManagerEvents()
is triggered which can be set toMeeting
class by usingsetAudioDeviceChangeListener()
.
Example
- Kotlin
- Java
btnChangeMic!!.setOnClickListener { _: View? ->
// Change Mic during 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 during 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 ... >
//...
<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()
- By using
changeWebcam()
function, a participant can stream from front / rear camera during the meeting.
Example
- Kotlin
- Java
btnWebcam!!.setOnClickListener {
// Change Webcam during Meeting
meeting!!.changeWebcam()
}
btnWebcam.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Change Webcam during Meeting
meeting.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