Skip to main content
Version: 1.2.x

Change Audio Output Device - Flutter

During the meeting at any point a participant wishes to switch his/her output audio like from headphones to speaker, it can be done using the below mentioned methods.

important

This feature works for input and output device on Mobile apps, and for output device on Web and Desktop apps.

getAudioDevices()

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

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

switchAudioDevice()

  • After selecting the desired device, you can switch the audio output by passing the corresponding AudioDeviceInfo object as a parameter to the switchAudioDevice() method.
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>? speakers = [];

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

void fetchSpeakers() async {
List<AudioDeviceInfo>? audioDevices = await VideoSDK.getAudioDevices();
for (AudioDeviceInfo device in audioDevices!) {
if (device.kind == 'audiooutput') {
speakers?.add(device);
}
}
setState(() {});
}

@override
Widget build(BuildContext context) {
return Column(children: [
ElevatedButton(
child: const Text("Change Audio 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: speakers != null && speakers!.isNotEmpty
? Column(
children: speakers!
.map(
(device) => ElevatedButton(
child: Text(device.label),
onPressed: () {
_room.switchAudioDevice(device);
Navigator.pop(context);
},
),
)
.toList(),
)
: const Text("No Speaker Devices found."),
)
],
),
),
)
}),
]);
}
}
note

For iOS devices:

  • EARPIECE is not supported whenever WIRED_HEADSET or BLUETOOTH device is connected.
  • WIRED_HEADSET and BLUETOOTH devices are not supported simultaneously. Priority is given to the most recently connected device.

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