Skip to main content
Version: 1.2.x

Change Audio Input Device - Flutter

During the meeting at any point a participant wishes to switch his/her input audio device, it can be done using the below mentioned methods.

important

This feature is only available on the Web and Desktop; if you want to use it on Mobile, please refer this guide.

getAudioDevices()

  • The getAudioDevices() method will help you to list down all possible connected audio input devices which will return a list of AudioDeviceInfo objects.

  • The AudioDeviceInfo object will contain the deviceId , kind , groupId and label for the device.

changeMic()

  • After selecting the desired device, you can switch the audio input by passing the corresponding AudioDeviceInfo object as a parameter to the changeMic() method.

Example

import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class MeetingScreen extends StatefulWidget {
const MeetingScreen({Key? key}) : super(key: key);

@override
_MeetingScreenState createState() => _MeetingScreenState();
}

class _MeetingScreenState extends State<MeetingScreen> {
late Room _room;
List<AudioDeviceInfo>? mics = [];

@override
void initState() {
super.initState();
fetchMics();
}

void fetchMics() async {
List<AudioDeviceInfo>? audioDevices = await VideoSDK.getAudioDevices();
if (kIsWeb || Platform.isMacOS || Platform.isWindows) {
for (AudioDeviceInfo device in audioDevices!) {
if (device.kind == 'audioinput') {
mics?.add(device);
}
}
}
setState(() {});
}

@override
Widget build(BuildContext context) {
return Column(children: [
ElevatedButton(
child: Text("Change Input Device"),
onPressed: () => {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text("Select Audio Device"),
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SingleChildScrollView(
reverse: true,
child: mics != null && mics!.isNotEmpty
? Column(
children: mics!
.map(
(device) => ElevatedButton(
child: Text(device.label),
onPressed: () {
_room.changeMic(device);
Navigator.pop(context);
},
),
)
.toList(),
)
: const Text("No Microphone Devices found."),
)
],
),
),
)
}),
]);
}
}

API Reference

The API references for all the methods and events utilized in this guide are provided below.

Got a Question? Ask us on discord