Skip to main content
Version: 1.0.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.

Getting Output Device​

getAudioOutputDevices() method will help you to list down all possible connected audio devices which will return a list of MediaDeviceInfo objects.

MediaDeviceInfo will contain the deviceId and label for the device.

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

class MeetingScreen extends StatefulWidget {
...
}

class _MeetingScreenState extends State<MeetingScreen> {
late Room _room;

@override
void initState() {
...
}

@override
Widget build(BuildContext context) {
return Column(
children:[
ElevatedButton(
child: Text("Get Output Device"),
onPressed: () => {
List<MediaDeviceInfo> outputDevice = _room.getAudioOutputDevices()
log(outputDevice);
}),
]
);
}
}

Switching Audio Device​

You can switch the audio output device by using the switchAudioOutput() which will take the MediaDeviceInfo object as parameter to which you want to switch the audio output.

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

class MeetingScreen extends StatefulWidget {
...
}

class _MeetingScreenState extends State<MeetingScreen> {
late Room _room;

@override
void initState() {
...
}

@override
Widget build(BuildContext context) {
return Column(
children:[
ElevatedButton(
child: Text("Change Output 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: Column(
children: _room
.getAudioOutputDevices()
.map(
(device) => ElevatedButton(
child: Text(device.label),
onPressed: () => {
_room.switchAudioDevice(device),
Navigator.pop(context)
},
),
)
.toList(),
),
)
],
),
),
);
}),
]
);
}
}
note

EARPIECE is not supported whenever WIRED_HEADSET or BLUETOOTH device is connected.

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