setVideoInputDevice method
- MediaDevice device
Set video input device.
Implementation
Future<void> setVideoInputDevice(MediaDevice device) async {
final track = localParticipant?.videoTrackPublications.firstOrNull?.track;
final currentDeviceId = engine.roomOptions.defaultCameraCaptureOptions.deviceId;
// Always update roomOptions so future tracks use the correct device
engine.roomOptions = engine.roomOptions.copyWith(
defaultCameraCaptureOptions: roomOptions.defaultCameraCaptureOptions.copyWith(deviceId: device.deviceId),
);
try {
if (track != null && currentDeviceId != device.deviceId) {
await track.switchCamera(device.deviceId);
Hardware.instance.selectedVideoInput = device;
}
} catch (e) {
// if the switching actually fails, reset it to the previous deviceId
engine.roomOptions = engine.roomOptions.copyWith(
defaultCameraCaptureOptions: roomOptions.defaultCameraCaptureOptions.copyWith(deviceId: currentDeviceId),
);
}
}