Switch Audio Output (BETA) - Flutter
This feature will help you to switch audio output device during the session.
Get Connected Device List
This method will help you to list down all possible connected audio devices.
To get the list of all available audio output devices, use VideoSDK.getMics(), which will return a list of MicrophoneDeviceInfo.
MicrophoneDeviceInfo will contain the deviceId and label of the particular audio output device. On Android, the devices are SPEAKER_PHONE, EARPIECE, WIRED_HEADSET and BLUETOOTH, and label is the same string as deviceId.
ElevatedButton(
child: Text("Get Output Device"),
onPressed: () async {
List<MicrophoneDeviceInfo>? outputDevices = await VideoSDK.getMics();
log("${outputDevices?.map((device) => device.label).toList()}");
},
),
Switch Audio to Another Device
This method will help you to switch specific audio output device.
- On Android and iOS, the microphone and the speaker share one audio route, so this changes both. The microphone stays muted or unmuted as it was.
setAudioDevice()returns aFuturethat throws aVideoSDKErrorwhen the SDK refuses the call, soawaitit insidetry/catch.
try {
// Pass the MicrophoneDeviceInfo object to which the audio is to be switched.
await room.setAudioDevice(audioDeviceInfo);
} on VideoSDKError catch (error) {
log("setAudioDevice failed: ${error.code} ${error.name}");
}
VideoSDK.getSelectedAudioDevice() returns the audio device in use, from join on. It is null before join.
Listen for Device Changes
To know when a headset or Bluetooth device connects or disconnects, set a listener on the room. It receives the device now in use and every available device. Pass null to stop listening.
room.setAudioDeviceChangeListener(
(MicrophoneDeviceInfo? selectedDevice, List<MicrophoneDeviceInfo> devices) {
log("Audio is on ${selectedDevice?.label}; ${devices.length} devices available");
},
);
On Android, switching to EARPIECE has no effect while a WIRED_HEADSET device is connected.
To check the implementation of switch audio device in detail, check out the Flutter Code Sample
Got a Question? Ask us on discord

