Skip to main content

Camera and Microphone

Working with hardware devices can always have some level of complexity to it but the SDK does a lot to abstract the complexities and expose an intuitive interface for querying the connected devices and changing them throughout the call.

For turning the user’s camera on and off, the following methods can be invoked directly on the Call class:

call.setMicrophoneEnabled(enabled: true);
call.setCameraEnabled(enabled: true);
note

As a reminder, before attempting to access the user’s connected devices, please ensure the appropriate permissions are set in both the iOS plist file and Android Manifest.

Camera Operations

Conveniently attached to the Call class are a series of methods which can be used to flip the device’s camera, set the camera position and disable the camera all together.

final call = StreamVideo.instance.makeCall(callType: StreamCallType(), id: 'MY-CALL');
call.flipCamera();
call.setCameraPosition(CameraPosition.front);
call.setCameraEnabled(enabled: false);

Microphone Operations

Similar the Camera API, the Call object also includes methods for performing audio actions like disabling the audio devices, configuring the audio input device and audio output device.

call.setAudioInputDevice(device);
call.setAudioOutputDevice(device);
call.setMicrophoneEnabled(enabled: true);

Listing Connected Devices

There may be cases where it becomes necessary to query all of the connected devices or listen to hardware changes such as when the user connects a new microphone or camera to their machine.

For this, the RtcMediaDeviceNotifier can be used. Encapsulated in this class are methods and listeners for interacting with all connected devices.

RtcMediaDeviceNotifier.instance.onDeviceChange.listen((devices) {
final audioInputDevice = devices.where((device) => device.kind == RtcMediaDeviceKind.audioInput);
call.setAudioInputDevice(audioInputDevice.first);
});

For the times where listening to hardware changes are not required, convince methods can be used to fetch the connected devices by their RtcMediaDeviceKind.

final videoDevices = RtcMediaDeviceNotifier.instance.audioOutputs();
final outputDevices = RtcMediaDeviceNotifier.instance.audioInputs();
final inputDevices = RtcMediaDeviceNotifier.instance.videoInputs();

When it comes to audio devices, WebRTC classifies them as two types, Earpiece and Speaker. These can be used to sort and further filter the devices connected to your app.

Did you find this page helpful?