Skip to main content
Version: 1.2.x

Change Video Input Device - Flutter

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

getVideoDevices()

  • This method of the VideoSDK class will give you the list of all the available cameras which can be shown in a list.

  • This method will return an array of VideoDeviceInfo which will contain the deviceId , label , kind and groupId of the camera input devices.

changeCam()

  • After selecting the desired device, you can switch the camera input by passing the corresponding VideoDeviceInfo object as a parameter to the changeCam() method.

Example

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<VideoDeviceInfo>? cameras = [];

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

void fetchCameras() async {
cameras = await VideoSDK.getVideoDevices();
setState(() {});
}

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

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