switchMedia method
Implementation
Future<void> switchMedia(EnxController obj) async {
try {
if (kIsWeb) {
List list = await EnxRtc.getDevices();
Map<String, dynamic> device = convertMapToMap(list[0]);
List<dynamic> micList = device["micList"];
deviceList.value = micList.map((device) => device["label"]).toList();
} else {
deviceList.value = await EnxRtc.getDevices();
}
mediaDeviceList.clear();
for (var i = 0; i < deviceList.value.length; i++) {
var mediaDevice = MediaDeviceModel.name(deviceList[i], false, i);
mediaDeviceList.add(mediaDevice);
}
for (var mediaDevice in mediaDeviceList) {
if (mediaDevice.name == selectedMedia) {
mediaDevice.status = true;
selectedMediaDeviceModel.value = mediaDevice;
}
}
await showSwitchAudioDialog(context, obj); // Ensure await here
} catch (e) {
print('Error in switchMedia: $e');
// Handle any errors or exceptions here
}
}